GraphQL - variable not defined by operation

前端 未结 1 737
情深已故
情深已故 2021-01-18 20:22

My GraphQL schema is defined as:

type Query {
    getEntity(id: Int!): Entity
    getEntityUsers(entityId: Int!, statusId: Int): [User]
}

type Entity {
             


        
1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-18 20:40

    Every operation (query or mutation) must explicitly define any variables you use inside that operation. So if you have a variable called $statusId, the type for this variable must be specified as part of your operation definition:

    query getEntity($id: Int!, $statusId: Int) {
      # your selection set here
    }
    

    Where those variables are used within your query (whether at the root level, or elsewhere) is irrelevant -- they must always be defined as part of your operation definition.

    0 讨论(0)
提交回复
热议问题