Skip to content
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

fix: always inline and deduplicate fragment definitions #8971

Merged
merged 9 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rare-rats-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/visitor-plugin-common': patch
---

Always inline referenced fragments within their document. This prevents issues with duplicated fragments or missing fragments.
5 changes: 5 additions & 0 deletions .changeset/rotten-lizards-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/client-preset': patch
n1ru4l marked this conversation as resolved.
Show resolved Hide resolved
---

Allow passing fragment documents to APIs like Apollos `readFragment`
192 changes: 187 additions & 5 deletions dev-test/githunt/typed-document-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,59 @@ export const FeedEntryFragmentDoc = {
],
},
},
...VoteButtonsFragmentDoc.definitions,
...RepoInfoFragmentDoc.definitions,
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'VoteButtons' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Entry' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'score' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'vote' },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'vote_value' } }],
},
},
],
},
},
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'RepoInfo' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Entry' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'repository' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'description' } },
{ kind: 'Field', name: { kind: 'Name', value: 'stargazers_count' } },
{ kind: 'Field', name: { kind: 'Name', value: 'open_issues_count' } },
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'postedBy' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'html_url' } },
{ kind: 'Field', name: { kind: 'Name', value: 'login' } },
],
},
},
],
},
},
],
} as unknown as DocumentNode<FeedEntryFragment, unknown>;
export const OnCommentAddedDocument = {
Expand Down Expand Up @@ -629,7 +680,30 @@ export const CommentDocument = {
],
},
},
...CommentsPageCommentFragmentDoc.definitions,
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'CommentsPageComment' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Comment' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'postedBy' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'login' } },
{ kind: 'Field', name: { kind: 'Name', value: 'html_url' } },
],
},
},
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
{ kind: 'Field', name: { kind: 'Name', value: 'content' } },
],
},
},
],
} as unknown as DocumentNode<CommentQuery, CommentQueryVariables>;
export const CurrentUserForProfileDocument = {
Expand Down Expand Up @@ -721,7 +795,92 @@ export const FeedDocument = {
],
},
},
...FeedEntryFragmentDoc.definitions,
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'VoteButtons' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Entry' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'score' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'vote' },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'vote_value' } }],
},
},
],
},
},
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'RepoInfo' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Entry' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'repository' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'description' } },
{ kind: 'Field', name: { kind: 'Name', value: 'stargazers_count' } },
{ kind: 'Field', name: { kind: 'Name', value: 'open_issues_count' } },
],
},
},
{
kind: 'Field',
name: { kind: 'Name', value: 'postedBy' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'html_url' } },
{ kind: 'Field', name: { kind: 'Name', value: 'login' } },
],
},
},
],
},
},
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'FeedEntry' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Entry' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{ kind: 'Field', name: { kind: 'Name', value: 'commentCount' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'repository' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'full_name' } },
{ kind: 'Field', name: { kind: 'Name', value: 'html_url' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'owner' },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'avatar_url' } }],
},
},
],
},
},
{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'VoteButtons' } },
{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'RepoInfo' } },
],
},
},
],
} as unknown as DocumentNode<FeedQuery, FeedQueryVariables>;
export const SubmitRepositoryDocument = {
Expand Down Expand Up @@ -806,7 +965,30 @@ export const SubmitCommentDocument = {
],
},
},
...CommentsPageCommentFragmentDoc.definitions,
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'CommentsPageComment' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Comment' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'id' } },
{
kind: 'Field',
name: { kind: 'Name', value: 'postedBy' },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: 'login' } },
{ kind: 'Field', name: { kind: 'Name', value: 'html_url' } },
],
},
},
{ kind: 'Field', name: { kind: 'Name', value: 'createdAt' } },
{ kind: 'Field', name: { kind: 'Name', value: 'content' } },
],
},
},
],
} as unknown as DocumentNode<SubmitCommentMutation, SubmitCommentMutationVariables>;
export const VoteDocument = {
Expand Down
29 changes: 28 additions & 1 deletion dev-test/gql-tag-operations-masking-star-wars/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,33 @@ export const HeroDetailsWithFragmentDocument = {
],
},
},
...HeroDetailsFragmentDoc.definitions,
{
kind: 'FragmentDefinition',
name: { kind: 'Name', value: 'HeroDetails' },
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Character' } },
selectionSet: {
kind: 'SelectionSet',
selections: [
{ kind: 'Field', name: { kind: 'Name', value: '__typename' } },
{ kind: 'Field', name: { kind: 'Name', value: 'name' } },
{
kind: 'InlineFragment',
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Human' } },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'height' } }],
},
},
{
kind: 'InlineFragment',
typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Droid' } },
selectionSet: {
kind: 'SelectionSet',
selections: [{ kind: 'Field', name: { kind: 'Name', value: 'primaryFunction' } }],
},
},
],
},
},
],
} as unknown as DocumentNode<HeroDetailsWithFragmentQuery, HeroDetailsWithFragmentQueryVariables>;
Loading