Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration to load schema from github #1068

Open
BarryThePenguin opened this issue Jun 8, 2022 · 1 comment
Open

Configuration to load schema from github #1068

BarryThePenguin opened this issue Jun 8, 2022 · 1 comment

Comments

@BarryThePenguin
Copy link

BarryThePenguin commented Jun 8, 2022

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?

constructor({ cwd }: { cwd: string }) {
this.loaders = {
schema: new LoadersRegistry({ cwd }),
documents: new LoadersRegistry({ cwd }),
};
// schema
this.loaders.schema.register(new GraphQLFileLoader());
this.loaders.schema.register(new UrlLoader());
this.loaders.schema.register(new JsonFileLoader());
// documents
this.loaders.documents.register(new GraphQLFileLoader());
}

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
Copy link
Collaborator

ardatan commented Jun 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants