duplicate fragments within queries
See original GitHub issueDescribe the bug
When using fragments in queries which use fragements in multiple positions, the fragments are beeing repeated in the string concatenation, so that most server will complain about it Error: There can be only one fragment named "addressFields".
Your Example Website or App
https://github.com/bastiion/graphql-codegen-duplicate-fragments-issue
Steps to Reproduce the Bug or Issue
- formulate a query that uses same fragments within two other fragments
- run codegen
Expected behavior
fragments must be deduplicated
a work-arround can be ssen here, which would also be an entry point for a bug fix https://github.com/bastiion/graphql-codegen-duplicate-fragments-issue/commit/d08f51ecdd7c3cb6b7af68c7bd24aae5b4a5808a#diff-ca580bb0b9ca66ec74fb97288ee12d571481819ed8e689ea99b2d6ff79dacc24
Screenshots or Videos
No response
Platform
- “@graphql-codegen/cli”: “2.3.0”,
- “@graphql-codegen/fragment-matcher”: “~3.3.0”,
- “@graphql-codegen/introspection”: “~2.2.0”,
- “@graphql-codegen/typescript”: “~2.7.1”,
- “@graphql-codegen/typescript-document-nodes”: “~2.3.1”,
- “@graphql-codegen/typescript-operations”: “~2.5.1”,
- “@graphql-codegen/typescript-react-query”: “~3.6.1”,
Codegen Config File
overwrite: true
schema:
- http://localhost:9002/graphql
documents: 'graphql/**/*.graphql'
generates:
graphql/generated/index.ts:
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-react-query'
config:
pureMagicComment: true
fetcher:
func: ../fetcher#useFetchData
isReactHook: true
Additional context
example query:
fragment addressFields on Address {
address
city
}
fragment personFields on Person {
name
address {
...addressFields
}
}
query company {
company {
name
address {
...addressFields
}
employees {
...personFields
}
}
}
will produce:
export const AddressFieldsFragmentDoc = /*#__PURE__*/ `
fragment addressFields on Address {
address
city
}
`;
export const PersonFieldsFragmentDoc = /*#__PURE__*/ `
fragment personFields on Person {
name
address {
...addressFields
}
}
${AddressFieldsFragmentDoc}`;
export const CompanyDocument = /*#__PURE__*/ `
query company {
company {
name
address {
...addressFields
}
employees {
...personFields
}
}
}
${AddressFieldsFragmentDoc}
${PersonFieldsFragmentDoc}`;
Issue Analytics
- State:
- Created a year ago
- Reactions:6
- Comments:14
Top Results From Across the Web
Fragment duplication on Fragment Transaction - Stack Overflow
I have tried referencing the fragments parent view to replace it, and the fragment itself (by id) and still, it only adds the...
Read more >Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. ... Every fragment includes a subset...
Read more >Duplicate fragments errors - Dgraph Cloud
I am building an app using Dgraph Cloud and found unexpected behaviour when using fragments. I am not able to use duplicate fragments...
Read more >Code Inspection: Duplicated code fragment - DataGrip
The inspection options allow you to select the scope of the reported duplicated fragments and set the initial size for the duplicated language ......
Read more >Fragments | Relay
Instead, they need to be included in a query, either directly or transitively. This means that all fragments must belong to a query...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can confirm it’s working for me with v1.1.2!
Good work @tojump + @charlypoly, thanks! 🎉
@tojump, I’ve released your contribution; thanks!
@AssisrMatheus @bernharduw, could you try with
@graphql-codegen/client-preset@1.1.2
? 📦