简体   繁体   中英

Using variables in typeScript graphQL code generator

I followed this tutorial to auto generate the schema of my graphql endpoint in my front application.

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.

Yes you can, you will usually have exported types in the generated file such as GetTodoVariables

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