-
Notifications
You must be signed in to change notification settings - Fork 348
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
Introducing new transform to override schema field config #2772
Conversation
🦋 Changeset detectedLatest commit: b7f244a The changes in this PR will be included in the next version bump. This PR includes changesets to release 74 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
2578390
to
e59ef5d
Compare
3f2ac37
to
12834b0
Compare
@santino I think we can merge this :) You can add a changeset so we can release |
Hey @ardatan, Currently, this supports only In the meantime, this can be merged and released. |
043362a
to
b7f244a
Compare
Thanks @santino ! |
Description
GraphQL Mesh, and underlying GraphQL Tools, make it easy and convenient to extend schemas, merge schemas and types, add middlewares to resolvers (composers), and much more.
However, it seems there is not really a way to override parts of a schema, such as overriding types for fields.
This transform introduces this functionality.
The transform was initially meant to hoist fields, but during development, it became much more than that.
You can transform a field by selecting the base type and field name (current) and the target type and field name (to be).
This is very simple when you want to hoist fields.
However, the transform also allows you to pass additional
typeDefs
so that you can create new GraphQL Types to be used as a target (to be).The transform provides built-in functionality to hoist field values or replace the entire
fieldConfig
(including the resolver function) with the targeted one.However, it also allows adding a
composer
to each rule so that custom logic can be built on each resolver function.The composer is fundamental for instance when hoisting values for fields that have been renamed, especially on a bare schema, because the transform cannot be aware of the shape of the raw resolver result; so manual adjustments are necessary.
Obviously, the composer can be used to completely ignore the original resolver for a field and execute a new resolver function instead; which might be necessary when overriding fields in general (so beyond the hoisting scope).
Type of change
How Has This Been Tested?
I have added unit tests for the new transform.
These make a good example of how the transform can be used.
I plan to add more unit tests to cover scenarios where multiple config options are combined together.
Checklist:
Further comments
This PR is still a draft as it requires an agreement to be reached on the proposed transform.
Current transform only implements
bare
mode, we should define ifwrap
is required and estimate effort to get it working.I believe this transform has huge potential.
Moving forward we can extend functionalities to override input types and arguments for instance.