简体   繁体   English

在 typeScript graphQL 代码生成器中使用变量

[英]Using variables in typeScript graphQL code generator

I followed this tutorial to auto generate the schema of my graphql endpoint in my front application.我按照本教程在我的前端应用程序中自动生成了我的 graphql 端点的模式。

However now I need to use variables, so I did something like this:但是现在我需要使用变量,所以我做了这样的事情:

export const GET_TODO = gql`
  query GetTodo($id: Int!) {
    todos(id: $id) {
        id
        text
        completed
      }
    }
  }

I want to know if there is a way I can get the variable type "automatically" without having to redefine it in the front.我想知道是否有一种方法可以“自动”获取变量类型,而不必在前面重新定义它。 Eg例如

...
 query GetTodo($id: AutoGeneratedTodoIdType) {
...

PS: I am using react, in case there are framework/library specific solutions. PS:我正在使用 React,以防有特定于框架/库的解决方案。

Yes you can, you will usually have exported types in the generated file such as GetTodoVariables是的,您通常会在生成的文件中导出类型,例如GetTodoVariables

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

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