[英]Can relay-compiler read the schema from an endpoint (http or https)?
Relay's ahead-of-time compilation generates new compiled artifacts. Relay 的提前编译会生成新的编译工件。 To be able to do that, it's necessary to pass the GraphQL schema path to its config file.
为此,必须将 GraphQL 模式路径传递给其配置文件。 My question is: can that path be a URL?
我的问题是:那条路径可以是 URL 吗? If not, what is the alternative way?
如果不是,有什么替代方法? The documentation is very vague about that.
文档对此非常模糊。
Why do I need it to be a URL?为什么我需要它成为 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.我使用的是
graphql get-schema
命令——它会生成远程模式的本地副本。 But the get-schema
command was deprecated in graphql-cli@4
.但是
get-schema
命令在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.
get-schema 不再可用在以前的版本中,您可以从端点内部给定的 >URL 将架构下载到 schemaPath 中的给定路径。 In the new version, schema refers to the endpoint of the schema.
在新版本中,schema 指的是 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:
如果您使用 Prisma 或在 URL 端点下提供架构的任何其他工具,您必须在配置 YAML 中使用以下语法指定它:
Source: https://github.com/Urigo/graphql-cli/blob/a8fc4bc6376205b2c6ee077cc0acfcef0712b470/docs/MIGRATION.md#get-schema-is-no-longer-available来源: 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
?也许唯一的选择是降级到
graphql-cli@3
?
It appears that relay-config
, unlike graphql-config
, does not accept a URL schema.与
graphql-config
不同, relay-config
-config 似乎不接受 URL 模式。 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: graphql-cli@4
迁移指南解释了如何下载模式,因为此功能不再是 package 的核心:
If you want to download the schema from this URL to your local file system, you will also need to install
codegen
plugin and itsschema-ast
plugin using the following command or its npm equivalent:如果您想从此 URL 下载模式到本地文件系统,您还需要使用以下命令或其 npm 等效命令安装
codegen
插件及其schema-ast
插件:yarn add @graphql-cli/codegen @graphql-codegen/schema-ast --dev
After that, you can specify the output path of the local schema file:
之后,您可以指定本地模式文件的 output 路径:
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.
通过运行 graphql 代码生成,schema.graphql 文件在项目的根路径中生成。
Source: https://github.com/Urigo/graphql-cli/blob/a8fc4bc6376205b2c6ee077cc0acfcef0712b470/docs/MIGRATION.md#get-schema-is-no-longer-available来源: https://github.com/Urigo/graphql-cli/blob/a8fc4bc6376205b2c6ee077cc0acfcef0712b470/docs/MIGRATION.md#get-schema-is-no-longer-available
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.