-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1031 Submission GQL Small Data Fetch #1060
Changes from 7 commits
7a7ea64
037bd55
3e20883
bbed438
0e6ce8a
07024f5
1dd4f7c
67ceec9
a603f09
7b08b56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,16 +80,26 @@ export const get = async (req: Request, res: Response) => { | |
return res.status(200).send(schema); | ||
}; | ||
|
||
export const getClinicalSchemas = async (withFields: boolean) => | ||
withFields | ||
? await manager | ||
.instance() | ||
.getSchemasWithFields() | ||
.then(result => | ||
result.filter( | ||
(s: manager.SchemaWithFields) => s.name !== ClinicalEntitySchemaNames.REGISTRATION, | ||
), | ||
) | ||
: await manager | ||
.instance() | ||
.getSchemaNames() | ||
.then(result => result.filter(s => s !== ClinicalEntitySchemaNames.REGISTRATION)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this logic the same apart from the instance method call? could be little more DRY. not sure which is the async call so not sure where to put await..something roughly likee.. export const getClinicalSchemas = async (withFields: boolean) => {
const managerInstance = await manager.instance();
const schemaNameFilter = (schemaName) => schemaName !== ClinicalEntitySchemaNames.REGISTRATION;
const schemas = withFields ? managerInstance.getSchemasWithFields().map(schema => schema.name) : managerInstance.getSchemaNames();
return schemas.filter(schemaNameFilter)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I had a feeling this could be improved. But, we don't want to map |
||
export const getClinicalEntities = async (req: Request, res: Response) => { | ||
const includeFields = req.query.includeFields as string; | ||
if (includeFields && includeFields.toLowerCase() === 'true') { | ||
const schemasWithFields = await manager.instance().getSchemasWithFields(); | ||
return res | ||
.status(200) | ||
.send(schemasWithFields.filter(s => s.name !== ClinicalEntitySchemaNames.REGISTRATION)); | ||
} | ||
const schemas = await manager.instance().getSchemaNames(); | ||
return res.status(200).send(schemas.filter(s => s !== ClinicalEntitySchemaNames.REGISTRATION)); | ||
const withFields = req?.query?.includeFields?.toLowerCase() === 'true'; | ||
const schemas = await getClinicalSchemas(withFields).then(result => result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's no need for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this was unnecessary, removed |
||
|
||
return res.status(200).send(schemas); | ||
}; | ||
|
||
export const getClinicalEntitiesData = async (includeFields: string) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,26 +22,24 @@ import { loggerFor } from '../../logger'; | |
|
||
const L = loggerFor(__filename); | ||
|
||
const clearClinicalRegistrationMutation = { | ||
clearClinicalRegistration: async ( | ||
obj: unknown, | ||
args: { | ||
shortName: string; | ||
registrationId: string; | ||
}, | ||
) => { | ||
const { shortName, registrationId } = args; | ||
return await operations | ||
.deleteRegistration(registrationId, shortName) | ||
.then(() => { | ||
L.info(`Deleted registrationId ${registrationId}`); | ||
return true; | ||
}) | ||
.catch(err => { | ||
L.error(`Failed to delete registration`, err); | ||
return false; | ||
}); | ||
const clearClinicalRegistration = async ( | ||
obj: unknown, | ||
args: { | ||
shortName: string; | ||
registrationId: string; | ||
}, | ||
) => { | ||
const { shortName, registrationId } = args; | ||
return await operations | ||
.deleteRegistration(registrationId, shortName) | ||
.then(() => { | ||
L.info(`Deleted registrationId ${registrationId}`); | ||
return true; | ||
}) | ||
.catch(err => { | ||
L.error(`Failed to delete registration`, err); | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice logging thumbs up emoticon |
||
}); | ||
}; | ||
|
||
export default clearClinicalRegistrationMutation; | ||
export default clearClinicalRegistration; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,23 +21,21 @@ import { GlobalGqlContext } from '../../app'; | |
import submissionAPI from '../../submission/submission-api'; | ||
import { convertClinicalSubmissionDataToGql } from '../utils'; | ||
|
||
const clearClinicalSubmissionResolver = { | ||
clearClinicalSubmission: async ( | ||
obj: unknown, | ||
args: { programShortName: string; fileType: string; version: string }, | ||
contextValue: any, | ||
) => { | ||
const { programShortName, fileType, version } = args; | ||
const response = await submissionAPI.clearFileDataFromActiveSubmission( | ||
programShortName, | ||
fileType || 'all', | ||
version, | ||
(<GlobalGqlContext>contextValue).egoToken, | ||
); | ||
return convertClinicalSubmissionDataToGql(programShortName, { | ||
submission: response, | ||
}); | ||
}, | ||
const clearClinicalSubmission = async ( | ||
obj: unknown, | ||
args: { programShortName: string; fileType: string; version: string }, | ||
contextValue: any, | ||
) => { | ||
const { programShortName, fileType, version } = args; | ||
const response = await submissionAPI.clearFileDataFromActiveSubmission( | ||
programShortName, | ||
fileType || 'all', | ||
version, | ||
(<GlobalGqlContext>contextValue).egoToken, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unclear why this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
return convertClinicalSubmissionDataToGql(programShortName, { | ||
submission: response, | ||
}); | ||
}; | ||
|
||
export default clearClinicalSubmissionResolver; | ||
export default clearClinicalSubmission; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,24 +23,22 @@ import { convertClinicalSubmissionDataToGql } from '../utils'; | |
import { DeepReadonly } from 'deep-freeze'; | ||
import { ActiveClinicalSubmission } from '../../submission/submission-entities'; | ||
|
||
const commitClinicalSubmissionResolver = { | ||
commitClinicalSubmission: async ( | ||
obj: unknown, | ||
args: { programShortName: string; version: string }, | ||
contextValue: any, | ||
) => { | ||
const { programShortName, version } = args; | ||
const submissionData = <DeepReadonly<ActiveClinicalSubmission>>( | ||
await submissionAPI.commitActiveSubmissionData( | ||
programShortName, | ||
version, | ||
(<GlobalGqlContext>contextValue).egoToken, | ||
) | ||
); | ||
return convertClinicalSubmissionDataToGql(programShortName, { | ||
submission: submissionData, | ||
}); | ||
}, | ||
const commitClinicalSubmission = async ( | ||
obj: unknown, | ||
args: { programShortName: string; version: string }, | ||
contextValue: any, | ||
) => { | ||
const { programShortName, version } = args; | ||
const submissionData = <DeepReadonly<ActiveClinicalSubmission>>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there one single way we can work around all this DeapReadonly stuff and stick with that approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this one we can handle by casting the return type of |
||
await submissionAPI.commitActiveSubmissionData( | ||
programShortName, | ||
version, | ||
(<GlobalGqlContext>contextValue).egoToken, | ||
) | ||
); | ||
return convertClinicalSubmissionDataToGql(programShortName, { | ||
submission: submissionData, | ||
}); | ||
}; | ||
|
||
export default commitClinicalSubmissionResolver; | ||
export default commitClinicalSubmission; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,21 @@ const typeDefs = gql` | |
Retrieve current stored Clinical Submission data for a program | ||
""" | ||
clinicalSubmissions(programShortName: String!): ClinicalSubmissionData! | ||
|
||
""" | ||
Retrieve current stored Clinical Submission Data Dictionary Schema version | ||
""" | ||
clinicalSubmissionSchemaVersion: String! | ||
|
||
""" | ||
Retrieve current Clinical Submission disabled state for both sample_registration and clinical entity files | ||
""" | ||
clinicalSubmissionSystemDisabled: Boolean! | ||
|
||
""" | ||
Retrieve current stored Clinical Submission Types list | ||
""" | ||
clinicalSubmissionTypesList(includeFields: String): [SchemaList]! | ||
} | ||
|
||
type Mutation { | ||
|
@@ -339,6 +354,8 @@ const typeDefs = gql` | |
oldValue: String! | ||
donorId: String! | ||
} | ||
|
||
scalar SchemaList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This scalar is a workaround for the issue in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you link me to more on this please? I don't understand and my gut is telling me that unions should be ok with primitives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They aren't: https://www.apollographql.com/docs/apollo-server/schema/unions-interfaces/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Going to sleep on it and review in the morning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good - let me know where the union is happening tomorrow please - I read the docs + github - very interesting - looks like unions don't work on scalars either
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh so this Union is related to getSchemasWithFields: #1060 (comment) |
||
`; | ||
|
||
export default typeDefs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has always returned either
[String] or [{ }]
; this does not play nicely w/ GraphQL TypeDefsOpen to suggestions + solutions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored for reusability (API vs GQL)
API is currently converting Clinical response to JSON, which masks difference btwn
[String] or [{ }]