You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When a graphql type definition has multiple @key directives (as in for Apollo Federation) AND that same type is extended elsewhere in the same schema being parsed by by the code generator, only the last directive is included in the output. I'm seeing this in both the schema-ast and typescript-resolvers plugin outputs.
To Reproduce
Steps to reproduce the behavior: Apply multiple @key directives to a type and elsewhere in the schema add fields to the type using the extend keyword. Use the schema-ast plugin to generate a parsed version of the schema and observe that only the last @key directive is in the output file. Make sure to configure both the 'federation' and 'includeDirectives' options configured to 'true'.
I've setup a codesandbox where this can be observed: https://codesandbox.io/s/zen-boyd-t8dls
Note: You can see all the directives successfully being included by commenting out the part of the schema that adds the 'phone' field to the User.
I'm peeling back the onion a little more and seeing another issue, though I don't fully understand it. If I tweak my individual schema files to not extend type User, the schema-ast that is generated seems correct. But the typescript-resolvers output is giving me trouble.
I get the following type definition for the __resolveReference resolver function: __resolveReference?: ReferenceResolver<Maybe<ResolversTypes['User']>, { __typename: 'User' } & (GraphQLRecursivePick<ParentType, {"id":true}> | GraphQLRecursivePick<ParentType, {"username":true}>), ContextType>;
But for some reason Typescript intellisense only thinks the reference input variable has a property of __typename and it doesn't think either "id" or "username" exist.
It's looking like this particular quirk is a typescript issue, because the following simplified test behaves the same way:
// Intellisense only complains about property "d" in initial assignment let test: { a: string } & ({ b: string } | { c: string }) = { a: "The", b: "United", c: "States", d: "of America" }; test.b = "hi"; // Intellisense thinks that only test.a exists here and complains
Describe the bug
When a graphql type definition has multiple
@key
directives (as in for Apollo Federation) AND that same type is extended elsewhere in the same schema being parsed by by the code generator, only the last directive is included in the output. I'm seeing this in both the schema-ast and typescript-resolvers plugin outputs.To Reproduce
Steps to reproduce the behavior: Apply multiple
@key
directives to a type and elsewhere in the schema add fields to the type using theextend
keyword. Use the schema-ast plugin to generate a parsed version of the schema and observe that only the last@key
directive is in the output file. Make sure to configure both the 'federation' and 'includeDirectives' options configured to 'true'.I've setup a codesandbox where this can be observed: https://codesandbox.io/s/zen-boyd-t8dls
Note: You can see all the directives successfully being included by commenting out the part of the schema that adds the 'phone' field to the User.
My GraphQL operations:
N/A
My
codegen.yml
config file:Expected behavior
The output should support having more than one
key
directive even when the type is extended elsewhereEnvironment:
@graphql-codegen/...
: 1.17.8Additional context
The text was updated successfully, but these errors were encountered: