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

Fix add extension types #830

Merged
merged 6 commits into from
Sep 27, 2023
Merged

Conversation

mgagliardo91
Copy link
Contributor

Description

Resolves graphile/graphile.github.io#368

This PR updates the makeExtendSchemaPlugin to add all new types to the schema during the GraphQLSchema hook so that they are available in the final schema, regardless of explicit usage. Up to this point, types were only added to the schema if they were explicitly (direct or recursively) mapped from a Query/Mutation.

Performance impact

Minimum - runs during the GraphQLSchema hook.

Security impact

N/A

Checklist

  • My code matches the project's code style and yarn lint:fix passes.
  • I've added tests for the new feature, and yarn test passes.
  • I have detailed the new feature in the relevant documentation.
  • I have added this feature to 'Pending' in the RELEASE_NOTES.md file (if one exists).
  • If this is a breaking change I've explained why.

Comment on lines 498 to 500
...(schema.types || []),
...typeExtensions.GraphQLSchema.types,
...newTypes,
Copy link
Member

Choose a reason for hiding this comment

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

This is great and very simple, but the problem is that it significantly changes the generated schema order - putting the types added by makeExtendSchemaPlugin above everything else.

I think that graphql walks the types in order, so we may be able to solve this fairly simply by just ensuring that the Query, Mutation and Subscription types are processed first. That might look something like this:

Suggested change
...(schema.types || []),
...typeExtensions.GraphQLSchema.types,
...newTypes,
...([
build.getTypeByName(inflection.builtin("Query")),
build.getTypeByName(inflection.builtin("Mutation")),
build.getTypeByName(inflection.builtin("Subscription")),
].filter(_ => _)),
...(schema.types || []),
...typeExtensions.GraphQLSchema.types,
...newTypes,

@benjie benjie merged commit 6e87476 into graphile:v4 Sep 27, 2023
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.

Hooks filtering out interface child types from makeExtendSchema
2 participants