graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Apollo Federation @key directive: "Nested fields in _FieldSet is not supported"

Open kevin-lindsay-1 opened this issue 5 years ago • 4 comments

Describe the bug Attempting to use nested fields in the @key directive returns an error, even though it's a supported syntax introduced in @apollo/federation.

To Reproduce Attempt to use nested fields in @key

Example:

type User @key(fields: "id organization { id }") {
  id: ID!
  organization: Organization!
}
✔ Parse configuration
  ❯ Generate outputs
    ❯ Generate src/generated/graphql.ts
      ✔ Load GraphQL schemas
      ✔ Load GraphQL documents
      ✖ Generate
        → Nested fields in _FieldSet is not supported

Not sure if this is technically a bug or just a missing feature, but I couldn't find anyone else having this issue elsewhere. Is it planned to be supported?

kevin-lindsay-1 avatar Sep 26 '19 21:09 kevin-lindsay-1

As a workaround, is there a way to simply ignore this particular error? Would be nice to have typedefs where it's supported but ignored where it's not.

--silent silences errors, but I'd prefer it to not silence everything, and generate code for whatever works, without feeling the need to avoid using nested fields in @key just because a code generator doesn't support it.

Since the schema is completely valid, I'd argue that this shouldn't even be an error, instead a warning that happens once when you try to generate code, with the preferred ability to silence.

kevin-lindsay-1 avatar Sep 26 '19 21:09 kevin-lindsay-1

It just a missing feature and we chose to throw an exception here because the output is incorrect, so the generation failed. We will implement it soon but if someone wants to help, reach out to us :)

kamilkisiela avatar Sep 27 '19 07:09 kamilkisiela

are there are any updates on this issue ? or how to fix it without the-S flag

khaled-osman avatar May 10 '22 13:05 khaled-osman

Any updates please?

xizhe-qiu avatar Aug 16 '22 20:08 xizhe-qiu

hi there, can someone confirm if this still an issue? tried to replicate with latest version of @graphql-codegen/cli(2.16.4) and couldn't reproduce the error.

What I've seen so far is likely the nested validation only being applied to the @provides directive now. https://github.com/dotansimha/graphql-code-generator/blob/%40graphql-codegen/cli%402.16.4/packages/utils/plugins-helpers/src/federation.ts#L255

I might be wrong, hope someone is able to test this as well.

UPDATE: found this test case which seems to confirm nested fields in @key directive are supported https://github.com/dotansimha/graphql-code-generator/blob/%40graphql-codegen/cli%402.16.4/packages/plugins/typescript/resolvers/tests/federation.spec.ts#L163

rubenbarreiro avatar Jan 20 '23 17:01 rubenbarreiro