GraphQL access fields

Hi, testing out GraphQL in Appfarm. Based on GraphQL documentation, you can do the following to fetch data with string matching.

query companyByName{
  company(name: "hei") {
    name
  }
}

However, as you can see from the first screen shot, this does not work. And the reason for that is because as you can see from the Company constructor in the GraphQL IDE for Appfarm, only sort, filter, skip and limit are fields in the constructor.

The question then is how I can access the actual fields of the Company object? As you can see from the screenshot below. If I access the type Company. I get the real fields. How can I access these in the query?

1 Like

I found the solution:

query {
  company(
    filter: {
      name: {
        eq: "Oslo"
      }
    }
  ) {
    name
  }
}

This works. However is there a simpler way of doing this, just by accessing name directly from the compan object?

1 Like

Hi!

That solution is correct. The only way to query data using GraphQL is to apply a filter to to query. Filters have more power than the parameter-filtering you suggest, but they have a bit more syntax.

2 Likes

I have another question @kristian .

I have the following query:

{
  Product: product(limit: 5, sort: {af_createdDate: DESC}, filter: {accountingID: {ne: null}}) {
    ProductNumber: productNumber
    ProductOwner: productOwner_reference {
      ProductOwnerName: name
      Company: company_reference {
        CompanyName: name
        ClientID: client  
      }
    }
  }
}

We want to fetch Product for ClientID eq “XYZ”. However, company_reference does not have a filter-attribute, so it is impossible to filter. How should we do it?

1 Like

Hi,
I’m facing this kind of challenge quite often. In order to achieve, this, I’m using a two step query:

  • First query the client object class with name: {eq: “XYZ”} and only retrieve the _id
  • Query the product object class with filtre on the clientID

But, if there’s an other way of doing this, i’ll be glad to hear

1 Like

Hi Jeremy.jean, we will wait to get suitable response as we are trying to do it in a single query. Also, note that it is at three levels Product - Owner - Company. Thank you for your inputs.