Apollo GraphQL:一个查询可以支持查找不同的查找字段吗?

Apollo GraphQL: Can One Query Support Lookup Different Lookup Fields?

我有一个看起来像这样的工作查询:

const GETONEASSOCIATE_QUERY = gql`
query getOneAssociate($_id: String!) {
  getOneAssociate(_id: $_id) {
    _id
    first_name
    last_name
    city
    state
    userIDinRelatedTable
  }
} `;

现在我希望能够通过 userIDinRelatedTable 查找同事。我是否必须编写一个全新的 graphQL 查询,或者是否有一种方法可以设置一个查询,以便我可以指定要用于查找的字段——类似于:

enter code here查询 getOneAssociate($_args: args) {

在此先感谢所有 thoughts/advice/info!

我猜在您的方案中,Associate 上有一个解析为 RelatedTable 的 userIDinRelatedTable 字段。

因此,要获取查询中返回的字段,您可以

const GETONEASSOCIATE_QUERY = gql`
  query getOneAssociate($_id: String!) {
    getOneAssociate(_id: $_id) {
    _id
    first_name
    last_name
    city
    state
    userIDinRelatedTable {
      id
      field1
      field2
    }
  }
} `;