简体   繁体   中英

Can relay-compiler read the schema from an endpoint (http or https)?

Relay's ahead-of-time compilation generates new compiled artifacts. To be able to do that, it's necessary to pass the GraphQL schema path to its config file. My question is: can that path be a URL? If not, what is the alternative way? The documentation is very vague about that.

Why do I need it to be a URL? My backend is in another service, so I have to find a way to access its schema. I was using the graphql get-schema command ─ which makes a local copy of the remote schema. But the get-schema command was deprecated in graphql-cli@4 .

get-schema is no longer available In previous versions, you were able to download the schema to the given path in schemaPath from >the URL given inside endpoint. In the new version, schema refers to the endpoint of the schema.

If you use Prisma or any other tool that provides your schema under URL endpoint, you must >specify it using the following syntax in your configuration YAML:

Source: https://github.com/Urigo/graphql-cli/blob/a8fc4bc6376205b2c6ee077cc0acfcef0712b470/docs/MIGRATION.md#get-schema-is-no-longer-available

Since then, I can't find a easy way to sync the remote schema with my front-end project. Maybe the only alternative is to downgrade to graphql-cli@3 ?

It appears that relay-config , unlike graphql-config , does not accept a URL schema. It must be a local path.

So, you have to keep using a local schema. The graphql-cli@4 migration guide explains how to download the schema since this functionality is not in the core of the package anymore:

If you want to download the schema from this URL to your local file system, you will also need to install codegen plugin and its schema-ast plugin using the following command or its npm equivalent:

 yarn add @graphql-cli/codegen @graphql-codegen/schema-ast --dev

After that, you can specify the output path of the local schema file:

 schema: http://localhost:4000/graphql extensions: codegen: generates: ./schema.graphql: plugins: - schema-ast

By running graphql codegen, the schema.graphql file is generated in the root path of your project.

Source: https://github.com/Urigo/graphql-cli/blob/a8fc4bc6376205b2c6ee077cc0acfcef0712b470/docs/MIGRATION.md#get-schema-is-no-longer-available

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM