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

v5 Roadmap #1306

Closed
22 tasks done
yaacovCR opened this issue Mar 26, 2020 · 5 comments
Closed
22 tasks done

v5 Roadmap #1306

yaacovCR opened this issue Mar 26, 2020 · 5 comments

Comments

@yaacovCR
Copy link
Collaborator

yaacovCR commented Mar 26, 2020

Track and try out the new alpha v5 releases.

New Features

Build

Transformation

Stitching

Utilities

Bug fixes:

@ardatan ardatan pinned this issue Mar 29, 2020
@bionicles
Copy link

How would a functional API look for directives?

For example, what would be the arguments to a directive function and what would / could we return from it?

@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Apr 2, 2020

@bionicles

You can currently (in next branch) use visitSchema to modify an existing schema (vs mapSchema which creates a new schema).

visitSchema takes an instantiated SchemaDirectiveVisitor or SchemaVisitor class
or an object of type SchemaVisitorMap that can define visitor functions for each graphql object type, see https://github.com/apollographql/graphql-tools/blob/next/src/Interfaces.ts#L443

You can also pass in a visitorSelector function instead of either of those to dynamically change how each object is visited, which is what is done when using schema directives:

https://github.com/apollographql/graphql-tools/blob/next/src/utils/SchemaDirectiveVisitor.ts#L141

The function instantiates the class to pass in the directive arguments here:

https://github.com/apollographql/graphql-tools/blob/next/src/utils/SchemaDirectiveVisitor.ts#L197

What could easily be done is passing in a special function instead of a SchemaDirectiveVisitor class. This function might take as its arguments the same arguments as the SchemaDirectiveVisitor constructor, but most importantly, the directive arguments, and could return a SchemaVisitorMap. Or, if implementers know which types they are visiting, they could do the extra discrimination and return the correct type visitor.

So, it would be a functional approach, the provided function for each named directive would take in all the info for each graphql object including the directive args and return an object containing a set of functions, one of which being the appropriate one, or the exact appropriate one.

@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Apr 2, 2020

But ideally, thinking more broadly, to allow directives specified on object fields to easily modify the input fields of the resolver arguments (see parallel approach https://github.com/profusion/apollo-validation-directives/blob/master/README.md#value-validation), we can think of a different architecture altogether that is more generic. The schema directive is meant to transform the schema, but perhaps a number of schema directives are meant to work together to modify a schema. A schema directive implementation should really be a function that takes a list of directive names (so users of schema directives can use whatever names they want, to prevent conflicts) and returns a function that takes a schema as an argument and returns a schema.

The implementation can rely on visitSchema or mapSchema to assess how the graphql objects are annotated and modify them accordingly.

An additional single exported helper would be useful to extract a map of the directives and their arguments from the AST

@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Apr 3, 2020

Moved several new features to #1337 so we could get v5 out as soon as possible.

@yaacovCR yaacovCR changed the title v5 roadmap v5 Roadmap Apr 3, 2020
@yaacovCR
Copy link
Collaborator Author

yaacovCR commented Apr 3, 2020

Let's continue discussion on how to easily use combinations of directives to modify schemas at #1234.

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

3 participants