简体   繁体   English

强类型 GraphQL 查询

[英]Strongly typed GraphQL queries

I'm setting up a project with Vue CLI, using axios as my request library.我正在使用 Vue CLI 设置一个项目,使用 axios 作为我的请求库。 All of the examples that I've seen uses a string as the query, eg我见过的所有示例都使用字符串作为查询,例如

{
  hero {
    name
    friends {
      name
    }
  }
}

Since I'm using typescript and have typings for the entities, is there any way to generate the query using some kind of fluent framework or similar, so that I can work with intellisense instead of plain strings?由于我正在使用打字稿并为实体打字,有没有办法使用某种流畅的框架或类似框架来生成查询,以便我可以使用智能感知而不是纯字符串?

Most clients require you to provide the query as a string.大多数客户端要求您以字符串形式提供查询。 You can use an IDE like GraphiQL, GraphQL Playground or Altair to provide features like autocompletion and syntax highlighting when writing your query.您可以使用 GraphiQL、GraphQL Playground 或 Altair 等 IDE 在编写查询时提供自动完成和语法突出显示等功能。 Certain editors also have plugins that offer similar functionality.某些编辑器也有提供类似功能的插件。 If you're using TypeScript, you can typically use something like GraphQL Code Generator or Apollo CLI to then generate the types based on your queries and your schema.如果您使用的是 TypeScript,您通常可以使用GraphQL 代码生成器Apollo CLI 之类的工具,然后根据您的查询和架构生成类型。

The only client I'm aware of that is generated from your schema , allowing you to use a fluent API instead, is GraphQL Zeus .我所知道的唯一客户端是GraphQL Zeus从您的 schema生成的,允许您使用流畅的 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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