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.

Hi,
When looking at the documentation of GraphQL queries (on the right side in GraphiQL), you can only filter on object class of the first level, so as far as I understand it, it’s just not possible (or not yet) to do that in a single query. But maybe someone from Appfarm can confirm or give insights about this feature request?

1 Like

It seems to be the case with AppFarm GraphQL implementation. But in general we should be able to define “resolver” to fetch any data. Let us wait for AppFarm response.

Hi, @kristian or someone else from Appfarm. Do you have any solutions for GraphQL access fields - #4 by SinanMaric? Thank you :slight_smile:

1 Like

Hi!

There is currently (and not in near-future) no possibilities for filtering sub-entities (such as in SQL where you may use exists in with some sub-query).

What is the use case, is it just for data exploration, og for using grapghQL as a way of integration? If the last one is the case, you may solve it using a Service Endpoint instead.

1 Like

By the way: could you instead query Company, with Filter, and then list project_list per Company?

1 Like

Hi @kristian, Use case is Integration and we want to send all related data via single query just like in case of SQL as you mentioned. Now that we have answer from you, we have already implemented multi query within Service Endpoint and that is got exposed to client for integration.

1 Like