Merging schemas from multiple APIs with similar types #8721
Unanswered
pedropmedina
asked this question in
Q&A
Replies: 1 comment 5 replies
-
|
codegen does not do any merging of schemas. In this case your best option is to have multiple generate targets for types. {
generates: {
'./src/gql/api1/': {
schema: apiUrl1,
preset: 'client',
plugins: [],
presetConfig: { fragmentMasking: { unmaskFunctionName: 'getFragmentData' } },
documents: ['!/src/codegen/**/*',], // --- 1
},
'./src/gql/api2/': {
schema: apiUrl2,
preset: 'client',
plugins: [],
presetConfig: { fragmentMasking: { unmaskFunctionName: 'getFragmentData' } },
documents: ['!/src/codegen/**/*',], // --- 1
},
},
ignoreNoDocuments: true,
overwrite: true,
}so the tricky part is how you structure you code. This is usually not a common pattern I see where the app is making calls to different GraphQL service. Based on what I see in your schema it looks like there are 2 different subgraphs of one service. So my recommendation is having a gateway that merges the sources so your API has only one service to make calls to. Or the other option is you do client side compositions and you use the composed schema to generate types for your app. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Can someone explains how codegen handles merging schemas? In an instance where I have two GraphQL APIs in the top schema config that each contains same named types with different fields, how would codegen handle it and what's the best option in this case to preserve the types?
How would codegen handle the above?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions