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

Functional Schema Directives don't execute in LTR order as Legacy SchemaVisitor or directive resolvers #1606

Closed
suparngp opened this issue Jun 6, 2020 · 4 comments

Comments

@suparngp
Copy link

suparngp commented Jun 6, 2020

The behavior of schema transform based directive and SchemaVisitor based directives seems to be different in regards to their execution order if you specify multiple directives. For example

directive @map on FIELD_DEFINITION
directive @filter on FIELD_DEFINITION
# usage
type MyType {
    list1: [String!]! @map @filter
    list2: [String!]! @filter @map
}
const schema = makeExecutableSchema({
  schemaTransforms: [mapDirective, filterDirective] // vs [filterDirective, mapDirective]
});

In this case, map always executed before filter regardless of placement on the field. I believe that schemaTransforms being an array introduces this order.

Are these two apis (SchemaVisitor vs functional) supposed to be interchangeable or complementary, especially since schemaDirectives is marked as Legacy?

Is there an example where I can see how to rewrite a directive with the new API while preserving the order?

@yaacovCR
Copy link
Collaborator

yaacovCR commented Jun 7, 2020

You would combine whatever directives you need to be in LTR order (or any other order) into a single transformation function and pass multiple directive names as needed. This is essentially how directiveResolvers are currently implemented......

@yaacovCR
Copy link
Collaborator

yaacovCR commented Jun 7, 2020

This should be better documented...

@suparngp
Copy link
Author

suparngp commented Jun 7, 2020

If I understand correctly, I'd have to create a new directive / transform for every combination of these directives. I cannot reuse them by declaring them in the schema in different orders like directiveResolvers? Or may be create a new directive which accepts a list of other directive names (or transform names per say) and applies them in order? While either approaches don't feel intuitive, they do solve my use cases. It would make sense to clarify in the docs which approach to create directives should be preferred because at the moment, it seems that both schemaDirectives and directiveResolvers are considered legacy vs the mapSchema based functional api but there is a clear gap in the out of the box functionality in the new vs old apis.

For now, I created a new function attachSchemaTransforms similar to attachDirectiveResolvers which takes a map of transforms and their names and applies them in order after calling makeExecutableSchema.

Feel free to close this issue since my original question is clarified and there are approaches to solve these use cases.

@yaacovCR
Copy link
Collaborator

yaacovCR commented Jun 9, 2020

Closing, thanks so much!

@yaacovCR yaacovCR closed this as completed Jun 9, 2020
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

No branches or pull requests

2 participants