0

I have a client that queries 2 endpoints. Now, how do I auto-generate types from 2 graphql schemas, when using 2 endpoints?

Scripts I used up until now (with standard 1 endpoint) uses Apollo codegen (source):

"schema": "npx apollo service:download --endpoint=http://localhost:8080/graphql graphql-schema.json",
"types": "npm run schema && apollo client:codegen --localSchemaFile=graphql-schema.json --variant=development --target=typescript --addTypename --queries=./src/**/*.graphql --useReadOnlyTypes --globalTypesFile=src/globalTypes.ts . && npm run prettier"

Possible solution is also generating 2 introspection schemas and then merging them together, I just didn't find how.

I'm also open to move to Graphql Code Generator.

Is there any example, guidance, or link please? Thank you

justdvl
  • 698
  • 4
  • 15

1 Answers1

1

GraphQL Code Generator supports configuring multiple schemas by merging their definitions automatically for you.

You will find some documentation on this matter here: https://www.the-guild.dev/graphql/codegen/docs/config-reference/schema-field#multiple-schemas-and-client-side-schema

Please note that schema can take an array of schema file paths or URLs.

Let us know if you need any guidance migrating from Apollo codegen.

Charly, from The Guild.

Charly Poly
  • 384
  • 1
  • 8
  • Thank you. I did just that - migrated to GrapQL Code Generator. If someone else is reading this, I basically just copied the solution (code, settings etc) found in some random public project. https://github.com/UrsaMaritimus/orca/blob/main/libs/graphql/README.md – justdvl Oct 21 '22 at 18:45