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

feat(import): allow configuring custom root fields #280

Closed

Conversation

nfantone
Copy link

@nfantone nfantone commented Feb 5, 2019

This PR stems from #42.

Allow extending the currently internal rootFields array with a custom mergeableTypes array.

const schema = importSchema('./schema.graphql', { mergeableTypes: ['Foo'] });

Types declared in mergeableTypes will be treated as root fields, just like Query, Mutation and Subscription. This effectively means:

  • They can be imported as Foo.*.
  • Fields across all imported files will be merged together in a single type.
  • Will appear at the top of the resulting SDL.

BREAKING CHANGE: importSchema API changed. It no longer receives schemas as its second, optional argument. Instead, it should be defined as a property in the new options argument.

const schemas = { appSchema, postsSchema, commentsSchema }

// Before
const schema = importSchema('./schema.graphql', schemas)

// Now
const schema = importSchema('./schema.graphql', { schemas })

@nfantone
Copy link
Author

nfantone commented Feb 6, 2019

I'm open to discussing how the new, optional mergeableTypes argument should be passed to importSchema.

  • A BREAKING CHANGE can be avoided by either making options a third argument (cumbersome if we don't really care about providing schemas) or by exporting a new function -in addition to importSchema-.
  • mergeableTypes could also be named something different, like customRootFields or additionalRootFields, more in line with vocabulary currently used by the documentation.

@ardatan
Copy link
Owner

ardatan commented Dec 24, 2019

Your changes has been merged into graphql-toolkit. Thank you!

@ardatan ardatan closed this Dec 24, 2019
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