How to merge openapi schemas under different namespaces? #5498
-
I'm putting together a GraphQL backend gateway for two HTTP REST APIs. The backend gateway does more than routing, like for example authorization related functions. For that reason I can't simply expose the HTTP REST APIs directly, I'm adding some custom logic between the externally-facing GraphQL API and the HTTP REST calls. I found out that I can use the graphql-mesh openapi plugin together with graphql-codegenerator, to generate a merged schema from the two openapi specifications. My problem is that the two openapis have some naming conflicts. Which leads to my question: is it possible to use namespaces for each openapis? This is what I'm trying to do in the schema:
API1:
loader: '@omnigraph/openapi'
source: "./schemas/api1_openapi.json"
ignoreErrorResponses: true
# namespace: API1 # <--- I'm looking for something like this
API2:
loader: '@omnigraph/openapi'
source: "./schemas/api2_openapi.json"
ignoreErrorResponses: true
# namespace: API2 # <--- I'm looking for something like this
generates:
./src/__generated__/resolvers-types.ts:
plugins:
- "typescript"
- "typescript-resolvers"
config:
useIndexSignature: true
contextType: "../resolver_context#ResolverContext"
./schemas/__generated__/merged.graphql:
plugins:
- schema-ast Without the namespaces this is the error what I get when running codegen:
Is there any existing solution / setting for this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You can use prefix transforms in a same Mesh configuration. Using omnigraph won't work as expected since it merges schemas barely. |
Beta Was this translation helpful? Give feedback.
But you still have "type: module" in your package.json. As i said earlier, you should either remove it or use the command as in the example I send above.