-
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
feat: override operation field types via directives #8071
feat: override operation field types via directives #8071
Conversation
Similar to DirectiveArgumentAndInputFieldMappings, add the ability to override the final operation types/nullability via field-level directives. The rationale behind this change is to allow clients to adjust the generated types/nullability within queries/fragments to match a corresponding server-side transformation (e.g. we have a @nonnull FIELD directive that causes our server to treat the field as required, this way we can ensure the types match) Previous discussion: dotansimha#5676 Further reading: https://github.com/graphql/graphql-wg/blob/main/rfcs/ClientControlledNullability.md#a-nonnull-custom-directive Co-authored-by: Jon Jensen <[email protected]>
🦋 Changeset detectedLatest commit: eea74b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 39 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 |
@izumin5210 is attempting to deploy a commit to the The Guild Team on Vercel. A member of the Team first needs to authorize it. |
I wonder whether it instead would make sense that the field types are wrapped within a generic. plugins:
config:
directiveFieldMappings:
asString: type AsStringTransform<_TIn> = string
nonNull: type NonNullTransform<TIn> = Exclude<TIn, null | undefined>
asBoolean: type AsBooleanTransform<_TIn> = boolean query MeQuery {
me {
id @asBoolean @asString
}
} type AsBooleanTransform<_TIn> = boolean
type Me = {
__typename?: 'User';
id: AsString<AsBooleanTransform<boolean>>;
}; |
Sorry for the delay in replying 🙇
I too think that is a great idea! I will update this pull request or create a new one! |
I updated the codes and PR description! could you review them? 🙏 |
We talked about this a lot and came to the conclusion that this is an anti-pattern. If you want special handling for a field you should use a custom scalar instead. See #1532 I am going to close this. |
Description
Add
directiveFieldMappings
option to typescript-operations plugin to overriding operation field types via directives.Related #7356
I fixed @jenseng's implementation to follow master and pass tests.
Example
Type of change
Please delete options that are not relevant.
Checklist:
Further comments
@required(entries: true)
,@as(type: "boolean")