将`where`对象传递给动态GraphQL查询

时间:2019-11-13 10:56:07

标签: graphql

说我有以下查询:

Foo($account: String!) {
  foo(where: { account: $account }) {
    id
    bar
  }
}

目前一切正常,但我可以将$account: String!参数替换为以下内容:

Foo($where: Object!) {
  foo(where: $where) {
    id
    bar
  }
}

1 个答案:

答案 0 :(得分:1)

是,但是您需要指定where的确切输入对象类型。哪种类型取决于您要查询的架构。

因此,如果您的模式是

type Query {
  foo(where: FooWhere!): Foo
}

input FooWhere {
  account: String
}

您的查询成为

Foo($where: FooWhere!) {
  foo(where: $where) {
    id
    bar
  }
}

如果您要查询某些第三方API,则它们应该提供文档或公开GraphiQL或GraphQL Playground接口,您可以在其中查找要使用的适当类型。

相关问题