-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add config option to omit export of empty fragment subtypes #7782
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
base: master
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
As a first-time contributor I'm not allowed to run the other workflows |
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.
Could you explain why you would want to introduce a flag for generating wrong types? Omitting the types of empty fragments can cause runtime errors as the TypeScript type would no longer mirror the actual GraphQL result type.
We use global unique IDs in our code base, and every queryable type implements """ Node, to make a type queryable, it needs to implement this interface. """
interface Node {
""" A node requires an ID. """
id: ID!
} Furthermore, every queryable type is queried via a spread: """ The query root. """
type Query {
""" Retrieves a Node through its ID. """
node(id: ID!): Node
}
type Person implements Node {
""" The ID of the person. """
id: ID!
""" Self explanatory. """
name: String
}
queried by export const PERSON_DATA_QUERY = gql`
query person($id: ID!) {
node(id: $id ) {
... on Person {
id
name
}
}
}
`; This is a flow that was well supported in old versions, but with new versions we run into the problem that the resulting generated type cannot be easily narrowed to only the person data. We'd either have to include the typename and add an extra check to every query result, or find a way to remove This MR thus introduces an optional way to reintroduce support for the previously existing behaviour where empty spreads were not added to the type. |
@peternedap is attempting to deploy a commit to the The Guild Team on Vercel. A member of the Team first needs to authorize it. |
Please also see the example in #6873. |
Description
Adds an extra config field for omitting empty objects when using inline fragment spreads in combination with
skipTypename
.This makes an upgrade from
@graphql-codegen/typescript-operations
version 1.18.0 to version 2 possible for people who run into problems with this. This also allows the upgrade from graphql 15 to 16, sincetypescript-operations
1.18 is incompatible with version 16.Related # (issue)
Type of change
Screenshots/Sandbox (if appropriate/relevant):
How Has This Been Tested?
Added unit tests:
Test Environment:
@graphql-codegen/...
: typescript-operationsChecklist:
Further comments
n/a