-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Inconsistent handling of directives in buildASTSchema and buildClientSchema #3419
Comments
@Cito Good question! The problem here is that Instead, we should refactor out new class
It can look like this: const schema = buildClientSchema(introspection);
const modyfiedSchema = extendSchema(schema, parse(extensionSDL));
const executableSchema = new GraphQLExecutableSchema(modyfiedSchema);
// ^ validation is done here + directives are added here
const response = execute({
executableSchema: executableSchema,
// graphql/validate/execute/etc. are not responsible for validating schema anymore
}); This way we will load "SDL" and "introspection" snapshots as is but will inject directives only if the schema is intended to be used execution. As an example of why we need such a non-trivial solution let's take @Cito What do you think? P.S. Setup described in graphql-python/gql#278 is invalid since "introspection" should be the result of execution it should include all standard directives. |
Also, I expected |
BTW. We also have inconsistency with assigning root type. For example:
But if you pass it as single SDL everything works fine:
My proposal is to have |
I agree, this should be in user code, and it could be class based, or a simple function. A new type is not strictly necessary, but may be beneficial. This is basically similar to the path taken by graphql executor where we assume users will call validateSchema as a separate step when necessary. |
The original question was about inconsistencies between
I read this as you possibly suggesting that within the core GraphQLSchema, the Query root type would not be defined at all (possibly never defined, possibly just not set up as "Query" by default, and that the userland GraphQLExecutableSchema class would be responsible for this? Or is that a typo, and you meant to say the following:
This would make sense to me, that any non trivial transformation logic should be in userland, whether it's in a new class or a new function. Are you able to clarify? Thanks! |
I noticed a difference in how specified (standard) directives are added by
buildASTSchema
vsbuildClientSchema
.In the former function, the specified directives are added automatically if they are missing.
In the latter function, the specified directives are not added automatically if they are missing.
I think this should be handled in the same way by both method - this different behavior caused some head-scratching here.
The main problem is
buildClientSchema
not adding the specified directives. Maybe we can change this to add them, first optionally, and then in the next major version by default?The text was updated successfully, but these errors were encountered: