kamilkisiela / graphql-config

One configuration for all your GraphQL tools (supported by most tools, editors & IDEs)
https://the-guild.dev/graphql/config
MIT License
1.17k stars 94 forks source link

Configuration to load schema from github #1068

Open BarryThePenguin opened 2 years ago

BarryThePenguin commented 2 years ago

Is your feature request related to a problem? Please describe.

I use the graphql-codegen cli to generate TypeScript types, etc, for my GraphQL schema. graphql-codegen is able to load the schema from GitHub using @graphql-tools/github-loader.

https://github.com/dotansimha/graphql-code-generator/blob/92fdaf4c518cc321fe51d98b82181592f61db485/packages/graphql-codegen-cli/src/graphql-config.ts#L18

I've defined the schema in my .graphqlrc.yaml file to load the schema from GitHub using the following config

documents: graphql/**/*.graphql
schema:
  - 'github:organisation/repository#develop:schema.graphql':
      token: ${GITHUB_TOKEN}
extensions:
  codegen:
    generates:
      ...

This works great, and I'm able to generate what I need..

I'm also using the VSCode GraphQL Extension, which in turn uses the graphql-language-service-server, which in turn uses graphql-config to load my .graphqlrc.yaml file.

However, it doesn't look like it's able to load the schema as I've defined it in my config. Instead I see the following message in the output for the GraphQL Language Server..

graphql-language-service-usage-logs: WARNING: graphql-config error, only highlighting is enabled:
fetch failed
for more information on using 'graphql-config' with 'graphql-language-service-server', 
see the documentation at https://www.npmjs.com/package/graphql-language-service-server#user-content-graphql-configuration-file

Describe the solution you'd like

Looking at how graphql-config loads the schema, it doesn't appear to have @graphql-tools/github-loader defined as a loader?

https://github.com/kamilkisiela/graphql-config/blob/6c935dbabd8959bd1c863c683c5336d92aaef4b3/src/extension.ts#L30-L42

Is it possible to add the github loader?

Describe alternatives you've considered

I briefly looked into using something like https://www.graphql-inspector.com to download the schema, and make it available locally, but I'm already using the Schema AST plugin for graphql-codegen, which I think is more suited for that task..

If I do have the schema available locally, how would configure the .graphqlrc.yaml file to download the schema from GitHub, but also point graphql-language-service-server to the local GraphQL schema?

ardatan commented 2 years ago

Is it possible to add the github loader?

Yes it is possible to add that loader; https://www.graphql-config.com/docs/library/author-extensions#registering-loaders They should add this on their own; https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-server You can create an issue on their repo.

If I do have the schema available locally, how would configure the .graphqlrc.yaml file to download the schema from GitHub, but also point graphql-language-service-server to the local GraphQL schema?

You can have one codegen configuration file that generates schema file then you can have a graphql config file for language server.