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

refactor application of transforms #1574

Merged
merged 1 commit into from Jun 4, 2020
Merged

refactor application of transforms #1574

merged 1 commit into from Jun 4, 2020

Conversation

yaacovCR
Copy link
Collaborator

@yaacovCR yaacovCR commented Jun 1, 2020

= provide binding option to delegateToSchema

A Binding is a function that takes a delegationContext (just the relevant subset of options passed to delegateSchema) and produces the set of transforms used to actually delegate (i.e. that "binds" the fieldNodes from the sourceSchema to that of the targetSchema), this provides library users ability to completely customize delegation behavior, even on a per field level. These delegation transforms are the specified schema transforms, but also the additional delegation transforms that reduce friction between the source and target schemas, see below.

= export defaultBinding that enables:

(a) setting arguments after schema transformation = AddArgumentsAsVariables
(b) conversion of original result into object annotated with errors for easy return and use with defaultMergedResolver = CheckResultAndHandleErrors
(c) addition of required selectionSets for use when stitching = AddSelectionSetsByField/Type, AddFragmentsByField
(d) automatic filtering of fields not in target schema, useful for stitching and many other scenarios = FilterToSchema
(e) delegation from concrete types in source schema to abstract types in target schema = WrapConcreteTypes
(f) delegation from new abstract types in source schema (not found in target schema) to implementations within target schemas = ExpandAbstractTypes

= addition of internal Transformer class responsible for applying transforms

The Transformer class is constructed with a delegationContext and a binding function and uses them to produces the delegating transforms. The Transformer creates an individual transformationContext for each transform (for easy sharing of state between the transformRequest and transformResult methods, a new feature) and exposes transformRequest and transformResult methods that performs the individual transformations with arguments of the original request/result, the delegationContext, and the individual transformationContext, which gives the transformRequest and transformResult methods access to the overall state, including the original graphql context, as well as any additional state they want to set up. These additional arguments may help enable advanced transforms such as specifying input fields in target schema not present or filtered from the source schema, see #1551.

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jun 3, 2020

The latest changes of this PR are available as alpha in npm: 6.0.8-alpha-b7b8996.0

Quickly update your package.json by running:

npx match-version @graphql-tools 6.0.8-alpha-b7b8996.0

@yaacovCR yaacovCR requested a review from ardatan June 3, 2020 02:53
@yaacovCR yaacovCR marked this pull request as ready for review June 3, 2020 02:53
@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Jun 3, 2020

I like the term binding, but does occupy similar semantic space to graphql-binding, although latter is about creating an sdk bound to a schema, I am talking about the binding of a field on source schema to request/response on target schema.

Looks like graphql-binding being superceded by graphql-mesh, so not much of an issue, but thought I would flag it.

= provide binding option to delegateToSchema

A Binding is a function that takes a delegationContext (just the relevant subset of options passed to delegateSchema) and produces the set of transforms used to actually delegate (i.e. that "binds" the fieldNodes from the sourceSchema to that of the targetSchema), this provides library users ability to completely customize delegation behavior, even on a per field level. These delegation transforms are the specified schema transforms, but also the additional delegation transforms that reduce friction between the source and target schemas, see below.

= export defaultBinding that enables:

(a) setting arguments after schema transformation = AddArgumentsAsVariables
(b) conversion of original result into object annotated with errors for easy return and use with defaultMergedResolver = CheckResultAndHandleErrors
(c) addition of required selectionSets for use when stitching = AddSelectionSetsByField/Type, AddFragmentsByField
(d) automatic filtering of fields not in target schema, useful for stitching and many other scenarios = FilterToSchema
(e) delegation from concrete types in source schema to abstract types in target schema = WrapConcreteTypes
(f) delegation from new abstract types in source schema (not found in target schema) to implementations within target schemas = ExpandAbstractTypes

= addition of internal Transformer class responsible for applying transforms

The Transformer class is constructed with a delegationContext and a binding function and uses them to produces the delegating transforms. The Transformer creates an individual transformationContext for each transform (for easy sharing of state between the transformRequest and transformResult methods, a new feature) and exposes transformRequest and transformResult methods that performs the individual transformations with arguments of the original request/result, the delegationContext, and the individual transformationContext, which gives the transformRequest and transformResult methods access to the overall state, including the original graphql context, as well as any additional state they want to set up. These additional arguments may help enable advanced transforms such as specifying input fields in target schema not present or filtered from the source schema, see #1551.
@yaacovCR yaacovCR merged commit b7b8996 into master Jun 4, 2020
@yaacovCR yaacovCR deleted the transformer branch June 4, 2020 02:10
@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Jun 4, 2020

Renamed it to DelegationBinding

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.

None yet

3 participants