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

Commits on Jun 4, 2020

  1. refactor application of transforms

    = 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 committed Jun 4, 2020
    Copy the full SHA
    9d593c1 View commit details
    Browse the repository at this point in the history