简体   繁体   中英

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

I've got a working query that looks like this:

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

Now I'd like to be able to look up an associate by userIDinRelatedTable . Do I have to write a whole new graphQL query, or, is there a way to set up a query so that I can specify what fields to be used for the lookup -- something like:

enter code here query getOneAssociate($_args: args) {

Thanks in advance to all for any thoughts/advice/info!

I'm guessing in your scheme you have a userIDinRelatedTable field on Associate which resolves to RelatedTable.

So to get the fields returned in your query you can

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

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