-
-
Notifications
You must be signed in to change notification settings - Fork 917
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
Add federation metadata extension methods and attributes #3958
Conversation
src/GraphQL/Federation/Extensions/FederationMetadataExtensions.cs
Outdated
Show resolved
Hide resolved
A lot of work for analyzers 🥴 |
I've got some ideas.... |
Ok the extension methods and attributes should all be scoped to the appropriate targets. |
Have not yet added url links within the xml comments |
/// <remarks> | ||
/// See <see href="https://www.apollographql.com/docs/federation/federated-types/federated-directives#key"/>. | ||
/// </remarks> | ||
public static TMetadataWriter Key<TMetadataWriter>(this TMetadataWriter graphType, string[] fields, bool resolvable = true) |
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 extension is useful to define compound or nested field keys. But I guess a single field as a key should be the most frequently used. Then need another extension based on IFieldMetadataWriter
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.
Actually, FieldBuilder implements IMetadataWriter
, so it works for all cases.
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.
But it doesn't implement IComplexGraphType
so it doesn't work...
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 don't follow you. @key
is only valid on an object or interface, which is what IComplexGraphType
is.
directive @key(fields: FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE
https://www.apollographql.com/docs/federation/federated-types/federated-directives#key
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.
As is implemented now, these methods simply add directives to the schema. They are not 'intelligent'; for example, you can't put [Key]
on a field and have it automatically add the proper directive to the graph type. While that's possible, it's not the current design.
So for @key
, you can do @key(fields: "id name pricing { id }")
by specifying this.Key("id name pricing { id }")
on the graph type.
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 see. Then, it can be enchantment in 8.1 if you prefer.
Yes let’s just get a workable version pushed out
Or at least merged in so we can review what further enhancements we want to make
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.
Btw key on interface is only supported sine v2.3. Adding it now will require adding version detection/configuration + validation.
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.
Yeah, we need to work on that (not yet in #3921 )
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.
Generally, I'm planning to have the proper directives added based on the version. Schema validation will already match up the applied directives to configured directives. So it will catch this error if it's the wrong version.
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.
having one target IObjectGraphType and the other target IInterfaceGraphType
Sounds better than implementing an analyzer to prevent incorrect usage. We can probably use the
[AllowedOn<>]
, but I'd prefer strongly typed API over static analysis.I’ll make the change
Done
Part 2 for #3921
Does not include the directive definitions