Skip to main content
Seasoned ⭐️⭐️
June 13, 2023
Solved

How to filter null values of FDM view's inherent property in GraphQL

Hi Team,

In GraphQL there is no (known) option to filter null values of FDM View’s direct properties which refer to another view(s).

For example: Consider the snapshot of the views.

Here if we want to filter all MyTypeWrapper instances which has ‘myType’ property as null.

How could it be achieved using GraphQL?

-Mohit

Expert ⭐️⭐️⭐️⭐️
July 18, 2023

@Mohit Shakaly
myType is a directRelation.  It’s type is defined by a (space, externalId) tuple. 

Apologies for the very delayed reply.   I’m using the null of the externalId as a measure of ‘null’ with respect to the direct relation.

# Based on the following model derived from the Actor/Movie example:


type PersonType @view(space: "test", version: "1") {
typename: String!
}

interface Person @view(space: "test", version: "1") {
typename: PersonType
name: String!
age: Int
}

#populate your Actors with 'actor' as the PersonType, do not populate the Directors with any typename

# using the following graphQL query, you'll get just 'Director' Persons
query MyQuery {
  listPerson(filter: {typename: {externalId: {isNull: true}}}) {
    items {
      name
      typename {
        typename
      }
    }
  }
}

 

 

fyi @Dilini Fernando 

3 replies

Dilini Fernando
Expert ⭐️⭐️⭐️⭐️
Expert ⭐️⭐️⭐️⭐️
June 14, 2023

Hi @Mohit Shakaly,

I have created a Support ticket, then our team can follow up and help you. 

Best regards,
Dilini

Expert ⭐️⭐️⭐️⭐️
July 18, 2023

@Mohit Shakaly
myType is a directRelation.  It’s type is defined by a (space, externalId) tuple. 

Apologies for the very delayed reply.   I’m using the null of the externalId as a measure of ‘null’ with respect to the direct relation.

# Based on the following model derived from the Actor/Movie example:


type PersonType @view(space: "test", version: "1") {
typename: String!
}

interface Person @view(space: "test", version: "1") {
typename: PersonType
name: String!
age: Int
}

#populate your Actors with 'actor' as the PersonType, do not populate the Directors with any typename

# using the following graphQL query, you'll get just 'Director' Persons
query MyQuery {
  listPerson(filter: {typename: {externalId: {isNull: true}}}) {
    items {
      name
      typename {
        typename
      }
    }
  }
}

 

 

fyi @Dilini Fernando 

Seasoned ⭐️⭐️
July 19, 2023

Thanks @Jason Dressel.