-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[resolvers][federation] Fix mapper being incorrectly used as the base type for reference #10216
base: federation-fixes
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a784d3b The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🚀 Snapshot Release (
|
Package | Version | Info |
---|---|---|
@graphql-codegen/visitor-plugin-common |
5.6.1-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-document-nodes |
4.0.13-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/gql-tag-operations |
4.0.13-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-operations |
4.4.1-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-resolvers |
4.4.2-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typed-document-node |
5.0.13-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript |
4.1.3-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/client-preset |
4.5.2-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/graphql-modules-preset |
4.0.13-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/plugin-helpers |
5.1.1-alpha-20241216083520-f3cad5e4c28fc18b31c96b0e186ce2261922c382 |
npm ↗︎ unpkg ↗︎ |
💻 Website PreviewThe latest changes are available as preview in: https://29d1ff2c.graphql-code-generator.pages.dev |
b3a8241
to
f5116a7
Compare
f3cad5e
to
c932044
Compare
if (resolvableKeyDirectives.length === 0) { | ||
return federationTypeSignature; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to return federationTypeSignature
instead of parentTypeSignature
when there's all @key
are resolvable=false
, I'm changing to return early here to make it easier to read as well
defsToInclude.push(`export type UnwrappedObject<T> = { | ||
[P in keyof T]: T[P] extends infer R | Promise<infer R> | (() => infer R2 | Promise<infer R2>) | ||
? R & R2 : T[P] | ||
};`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a given type:
export type ProductMapper = {
id: () => Promise<string>;
};
This type seems to return something like (() => Promise<string>) & string
which is unusual - How can a function intersect with a string?
Regardless, since we move from ParentType
to FederationType
, I don't think this is needed in the future.
public buildFederationTypes(): string { | ||
const federationMeta = this._federation.getMeta(); | ||
|
||
if (Object.keys(federationMeta).length === 0) { | ||
return ''; | ||
} | ||
|
||
const declarationKind = 'type'; | ||
return new DeclarationBlock(this._declarationBlockConfig) | ||
.export() | ||
.asKind(declarationKind) | ||
.withName(this.convertName('FederationTypes')) | ||
.withComment('Mapping of federation types') | ||
.withBlock( | ||
Object.keys(federationMeta) | ||
.map(typeName => { | ||
return indent(`${typeName}: ${this.convertName(typeName)}${this.getPunctuation(declarationKind)}`); | ||
}) | ||
.join('\n') | ||
).string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This FederationTypes
type will be used by federation entities to refer to the base types, similar to other types like ResolversParentTypes
and ResolversTypes
46219bc
to
01db0cc
Compare
01db0cc
to
bab88db
Compare
Note: current Examples Tests in CI are broken because of an unrelated issue. |
Description
__resolveReference
's first param (i.e. usually called "reference") can never be mappers because:__resolveReference
is only called by the gateway with data from@key
and/or@requires
__resolveReference
is never reached by the subgraph it is in, therefore it can never receive mapperThis PR creates a new
FederationTypes
to make it easier to target federation object types in entity types that need it.For example, the following
User
type is an entity withid
being the keySo, the
UserResolvers
would have some differences compared to normal types:FederationType extends FederationTypes['User'] = FederationTypes['User']
to target the baseUser
entity__resolveReference
usesFederationType
to pick the key usingGraphQLRecursivePick
Related #10206
Other notes
As part of change from
ParentType
->FederationType
, we no longer need theUnwrappedObject
added whenwrapFieldDefinitions = true
. This PR also removes this utility type and relevant codesType of change
How Has This Been Tested?