Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add option to squash exactly similar fragment types (#6826)
* feat: Add option to squash exactly similar fragment types When selecting from an interface, the default code path will declare the fragment type as a union of all implementing types. This happens regardless of whether we actually selecting something from the implementing types. E.g. ``` type FooFragment = | { __typename: "foo"; shared: string; } | { __typename: "bar"; shared: string; } ``` This behavior can be noisy and redundant. In combination with heavy use of interfaces, especially in nested schemas, this can also potentially trigger TypeScript's "union type is too complex to represent". In order to reduce the size of the generated fragments, we introduce the `mergeFragmentTypes` configuration option. When enabled, this will collapse all types with the same selection set to a single union member of the fragment type E.g. ``` type FooFragment = { __typename: "foo" | "bar"; shared: string; } ``` * Support skipTypename * Avoid mangling fragment type names unless we have to * Work around TS limits * Fix tests * Disable interface merging when masking inline fragments. While we'd ideally make this work, the way we determine type uniqueness would probably require a two-pass approach,n since we need to determine whether a type can be compacted before we add the fragment reference to the type (just adding the fragment reference straight away makes all types unique).
- Loading branch information
Showing
5 changed files
with
367 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@graphql-codegen/visitor-plugin-common': minor | ||
'@graphql-codegen/typescript-operations': minor | ||
--- | ||
|
||
feat: Add option to squash exactly similar fragment types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f1fb77b
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.
Successfully deployed to the following URLs:
graphql-code-generator – ./
graphql-code-generator-theguild.vercel.app
www.graphql-codegen.com
graphql-code-generator-git-master-theguild.vercel.app
graphql-code-generator.vercel.app
graphql-code-generator.com
graphql-codegen.com
www.graphql-code-generator.com