Describe the bug
I cannot generate the fragments when using federation.
To Reproduce
https://codesandbox.io/embed/graphql-codegen-issue-template-z5t3q
Expected behavior
Should run without errors.
@mikestaub why do you pass federation: true to fragment-matcher? It's not a valid option there.
Federation is a backend feature, and you should use it with typescript-resolvers only, and use it in your Federation backend.
@kamilkisiela and @ardatan noticed a different issue, some types are skipped and not being generated by fragment-matcher.
@mikestaub fragment-matcher generates introspection data only for unions and interfaces. You don't have any of those.
@dotansimha I am passing federation: true to fragment-matcher because if I don't I get this error: Unknown directive "key".
As a workaround, I am simply including this file in the schema list field:
scalar _Any
scalar _FieldSet
# a union of all types that use the @key directive
union _Entity = Asset | Product | User | UserGroup
type _Service {
sdl: String
}
extend type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
As defined here: https://www.apollographql.com/docs/apollo-server/federation/federation-spec/
Do you have an example of the fragment-matcher working with a federated schema?
Thanks @mikestaub . You are right.
At the moment, you can add those manually (add another item for schema field) and it will workaround this issue for your.
Me and @ardatan are thinking about doing a core change in the codegen that might fix that.
I am getting the Error even after set the workaround:
Couldn't find type Page in any of the schemas.
and the schema is:
extend type Page @key(fields: "id") {
id: ID! @external
}
You must add your custom types to the union like you see above:
union _Entity = Asset | Product | User | UserGroup | Page
Here is my Polyfill
# import * from "../types-generators/schema.graphql"
scalar _Any
scalar _FieldSet
# a union of all types that use the @key directive
union _Entity = Page
type _Service {
sdl: String
}
extend type Query {
_entities(representations: [_Any!]!): [_Entity]!
_service: _Service!
}
directive @external on FIELD_DEFINITION
directive @requires(fields: _FieldSet!) on FIELD_DEFINITION
directive @provides(fields: _FieldSet!) on FIELD_DEFINITION
directive @key(fields: _FieldSet!) on OBJECT | INTERFACE
# this is an optional directive discussed below
directive @extends on OBJECT
Are you sure there is a type Page { ... } in your schema?
Page is part of another federated project which is connected with this one, through the gateway.
Does this issue still persist?
Fixed in v1.10.0.
Most helpful comment
2508 should handle that