This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
forked from ardatan/graphql-tools
-
Notifications
You must be signed in to change notification settings - Fork 5
addResolversToSchema uses schema transforms that do not modify original schema #19
Comments
Will create new issue for B. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
In general, graphql-tools uses two methods to generate modified/new schemas:
Direct modification of existing schema: eg addResolversToSchema, addMockFunctionsToSchema, and the SchemaVisitor customizable approach.
Schema recreation: eg mergeSchemas, transformSchema base method, visitSchema and the individual schema transforms.
The difference is important. Although addResolversToSchemas returns the modified schema, some callers might rely on the fact that the reference to the original schema should also reflect the new resolvers.
This is fine as long as API is clear, but two problems are noted:
A: addResolversToSchemas can also be used to add definitions for enums/scalars, but then it also requires reparsing of default values. As currently implemented, this uses transforms that rely on visitSchema and do not modify the original schema. Callers that are using the returned value of addResolversToSchemas are fine, but if they are using the original reference, they would not get the new default values.
B: overall, visitSchema seems to be deprecated in favor of SchemaVisitor. The individual transforms can modify the passed schema or not, because the
true underlying original schema has already been wrapped at that point, so it would be ok to switch to SchemaVisitor or direct modification. It is ok to keep it this way, however. transformSchema uses a version of visitSchema that must recreate the schema and then updates resolvers. This could easily be refactored to recreate the schema with toConfig and then just use addResolversToSchemas to replace resolvers. This is also not strictly necessary, but if visitSchema can be completely deprecated, this action item might be a good long term goal.
The text was updated successfully, but these errors were encountered: