-
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
[federation][resolvers] Add generateInternalResolversIfNeeded. __resolveReference
to generate __resolveReference
only when resolvable
#9989
Conversation
🦋 Changeset detectedLatest commit: 5103ffd The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 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.5.0-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-document-nodes |
4.0.11-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/gql-tag-operations |
4.0.11-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-operations |
4.3.1-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript-resolvers |
4.4.0-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typed-document-node |
5.0.11-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/typescript |
4.1.1-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/client-preset |
4.5.0-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/graphql-modules-preset |
4.0.11-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
@graphql-codegen/plugin-helpers |
5.1.0-alpha-20241008120609-5103ffdfd3b1dde3243e745e73922d58be0c104f |
npm ↗︎ unpkg ↗︎ |
💻 Website PreviewThe latest changes are available as preview in: https://9d3f5c3e.graphql-code-generator.pages.dev |
9e14ec7
to
2063b04
Compare
e443756
to
06035ca
Compare
05dac21
to
3034c9a
Compare
18a679b
to
50b53f8
Compare
50b53f8
to
587899f
Compare
__resolveReference
if not resolvable__resolveReference
only when resolvable
export function checkObjectTypeFederationDetails( | ||
node: ObjectTypeDefinitionNode | GraphQLObjectType, | ||
schema: GraphQLSchema | ||
): { resolvableKeyDirectives: readonly DirectiveNode[] } | false { |
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.
I wanted to make the return type { resolvableKeyDirectives: readonly DirectiveNode[] } | undefined
, and make undefined
represent the case when the node is not a object type with federation.
However, the returned value is never undefined
(image attached) 🤔 So I've made it false
so at least typecheck works
@@ -275,7 +291,10 @@ export class ApolloFederation { | |||
* Checks if Object Type is involved in Federation. Based on `@key` directive | |||
* @param node Type | |||
*/ | |||
function isFederationObjectType(node: ObjectTypeDefinitionNode | GraphQLObjectType, schema: GraphQLSchema): boolean { | |||
export function checkObjectTypeFederationDetails( |
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 function checks whether a node has is federation, and returns federation metadata for the node (for now, it returns an array of resolvable @keys
)
I'm not very happy with the name checkObjectTypeFederationDetails
as it reads a bit clumsy 🤔 Open for suggestion.
@@ -656,7 +681,6 @@ export class BaseResolversVisitor< | |||
protected _globalDeclarations = new Set<string>(); | |||
protected _federation: ApolloFederation; | |||
protected _hasScalars = false; | |||
protected _hasFederation = false; |
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.
Previously, whenever there's a type with __resolveReference
, this will be set to true
.
Instead of a boolean
, we now want to track all the types with generated __resolveReference
types as output meta
, so downstream consumers (e.g. Server Preset) can easily use it.
The ApolloFederation
class now tracks this metadata.
I could just put it here as a property of the plugin e.g. _federationMeta
but it seems like ApolloFederation
is supposed to handle federation concerns. Happy to discuss if needed.
__resolveReference
only when resolvablegenerateInternalResolversIfNeeded. __resolveReference
to generate __resolveReference
only when resolvable
Description
From Apollo Federation doc: https://www.apollographql.com/docs/federation/federated-types/federated-directives/#resolvable: when there's no resolvable
@keys
on an object type in a subgraph, we cannot move to the object type in said subgraph.This PR:
generateInternalResolversIfNeeded.__resolveType
generateInternalResolversIfNeeded.__resolveType = false
generates optional__resolveType
without checking whether there's at least one resolvable@key
generateInternalResolversIfNeeded.__resolveType = true
:__resolveReference
if there's no resolvable@key
__resolveReference
for resolvable@key
and skip non-resolvable onesmeta
so something like Server Preset can handle it correctlyType of change
Please delete options that are not relevant.
Screenshots/Sandbox (if appropriate/relevant):
Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate
How Has This Been Tested?