Skip to content
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

Merged
merged 10 commits into from
Sep 25, 2023

Conversation

demariadaniel
Copy link
Contributor

@demariadaniel demariadaniel commented Sep 20, 2023

Description of changes

Type of Change

  • Bug
  • Refactor
  • New Feature
  • Release Candidate

Checklist before requesting review:

  • Check branch (code change PRs go to develop not master)
  • Check copyrights for new files
  • Manual testing
  • Regression tests completed and passing (double check number of tests).
  • Spelling has been checked.
  • Updated swagger docs accordingly (check it's still valid)
  • Set validationDependency in meta tag for Argo Dictionary fields used in code

@@ -80,16 +80,26 @@ export const get = async (req: Request, res: Response) => {
return res.status(200).send(schema);
};

export const getClinicalSchemas = async (withFields: boolean) =>
Copy link
Contributor Author

@demariadaniel demariadaniel Sep 20, 2023

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 TypeDefs
Open to suggestions + solutions

Copy link
Contributor Author

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 [{ }]

@@ -339,6 +354,8 @@ const typeDefs = gql`
oldValue: String!
donorId: String!
}

scalar SchemaList
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scalar is a workaround for the issue in /src/dictionary/api
clinicalSubmissionTypesList cannot return [String] | [SchemaWithFieldsObject]; unions cannot include primitives

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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/
Only allows Object types
Entire Github thread about it: graphql/graphql-spec#215

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to sleep on it and review in the morning
In Gateway, this is simply [String] because the response array is converted to JSON, so that may be what client expects and I should just stick to the same format
I was trying to format this to see the proper object for GQL Server purposes, which I think is ideal but might require client side changes

Copy link
Contributor

@ciaranschutte ciaranschutte Sep 20, 2023

Choose a reason for hiding this comment

The 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

All of a union's included types must be [object types](https://www.apollographql.com/docs/apollo-server/schema/schema/#object-types) (not scalars, input types, etc.). Included types do not need to share any fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh so this Union is related to getSchemasWithFields: #1060 (comment)
Where were either returning a String[] of Schema names or an array of SchemaWithFields objects

@demariadaniel demariadaniel changed the title WIP: Feat/1031 submission gql data fetch #1031 Submission GQL Small Data Fetch Sep 20, 2023
@demariadaniel demariadaniel marked this pull request as ready for review September 20, 2023 19:24
.instance()
.getSchemaNames()
.then(result => result.filter(s => s !== ClinicalEntitySchemaNames.REGISTRATION));

Copy link
Contributor

@ciaranschutte ciaranschutte Sep 20, 2023

Choose a reason for hiding this comment

The 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)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 getSchemasWithFields(), we need to return the objects with both names + fields, so schemaNameFilter needs to be called differently depending on value of withFields: 67ceec9

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's no need for then.
there's two different Promise methods at work here.
the chaining then and the more modern await - they both (in a simple case) do the same thing
waiting until Promise resolves and doing something it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this was unnecessary, removed

})
.catch(err => {
L.error(`Failed to delete registration`, err);
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice logging thumbs up emoticon

programShortName,
fileType || 'all',
version,
(<GlobalGqlContext>contextValue).egoToken,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unclear why this <GlobalGqlContext> is needed? Casting just the contextValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contextValue: any,
) => {
const { programShortName, version } = args;
const submissionData = <DeepReadonly<ActiveClinicalSubmission>>(
Copy link
Contributor

Choose a reason for hiding this comment

The 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?
I think this works out the same as using as DeepReadonly....
A utility function or a type guard that can be the de facto way for reusability, single point of functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 commitActiveSubmissionData: {} as DeepReadonly<ActiveClinicalSubmission>

7b08b56

ciaranschutte
ciaranschutte previously approved these changes Sep 20, 2023
Copy link
Contributor

@ciaranschutte ciaranschutte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demariadaniel left some questions & suggestions - approving

@demariadaniel demariadaniel merged commit 3f49f05 into develop Sep 25, 2023
@demariadaniel demariadaniel deleted the feat/1031-submission-gql-data-fetch branch September 25, 2023 14:20
@demariadaniel demariadaniel mentioned this pull request Oct 13, 2023
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants