写GraphQL时,IntelliJ的插件非常方便

js-graphql-intellij-plugin是一个用于JavaScript开发环境中的GraphQL插件。
以下是在此处公开的插件。
https://github.com/jimkyndemeyer/js-graphql-intellij-plugin
功能可以被概括成一个产品或系统所具备的所有操作和任务。
-
- 自動補完
-
- シンタックスハイライト
- クライアント機能
安裝

设定

在这里选择创建graphql.config.json文件。
然后在根目录下。
-
- graphql.config.json
- graphql.schema.json
此将自动生成。
graphql.config.json是配置文件。
graphql.schema.json是模式文件的样本。
在此配置文件中,我们将设置端点和模式。
如果存在API的schema.json
如果已经存在一个与API连接的scheme.json文件,则将其替换为graphql.schema.json。
此外,配置方面,如果在graphql.config.json的以下file部分指定了scheme.json的路径,则将读取该路径下的文件。
"README_file" : "Remove 'file' to use request url below. A relative or absolute path to the JSON from a schema introspection query, e.g. '{ data: ... }' or a .graphql/.graphqls file describing the schema using GraphQL Schema Language. Changes to the file are watched.",
"file": "graphql.schema.json",
如果没有schema.json
自動的にエンドポイントからshcema.jsonを解析し、Intellij上で作成、補完、ハイライトを行います。
"README_file" : "Remove 'file' to use request url below. A relative or absolute path to the JSON from a schema - -introspection query, e.g. '{ data: ... }' or a .graphql/.graphqls file describing the schema using GraphQL Schema Language. Changes to the file are watched.",
- "file": "graphql.schema.json",
将该网址的部分更改为终点URL。
在下面的示例中,我们将使用在本地启动的Pokemon API。
"README_request" : "To request the schema from a url instead, remove the 'file' JSON property above (and optionally delete the default graphql.schema.json file).",
"request": {
+ "url" : "http://localhost:5000/",
"method" : "POST",
当您保存后,会在IntelliJ上生成一个schema文件,如下图所示。
通过这个文件,您可以查看已定义的type等内容,非常方便!
(如果出现错误,请检查您的端点是否错误或者是否缺少选项(如认证等)的设置。)

设定用于从Intellij发出查询的端点。
如果有 shceme.json,则可以通过编辑 graphql.config.json 中以下URL部分来从 Intellij 中发起查询,即使 shceme.json 不存在也可以。
"README_endpoints": "A list of GraphQL endpoints that can be queried from '.graphql' files in the IDE",
"endpoints" : [
{
+ "name": "pokemon",
+ "url": "http://localhost:5000/",
"options" : {
"headers": {
"user-agent" : "JS GraphQL"
}
}
}
]
尝试使用



非常方便!