Score:0

Filtering on child properties in GraphQL

hu flag

I am using GraphQL to get a list of upcoming events. I am having trouble finding the correct way to filter on the date value which is a child of my date field.

The query, which works:

query getUpcomingEvents {
  nodeQuery(
    filter: {
      conditions: [
        {operator: EQUAL, field: "type", value: ["ain_event"]},
        {operator: EQUAL, field: "status", value: ["1"]} 
      ]
    }
  )
  {
    entities {
      entityLabel
      ...on NodeAinEvent {
        fieldAinEventLocation
        fieldAinEventDate {
          startDate
          endDate
        }
        fieldAinLink {
          uri
        }
      }
    }
  }
}

I get this response:

 {
  "data": {
    "nodeQuery": {
      "entities": [
        {
          "entityLabel": "EAA AIRVENTURE",
          "fieldAinEventLocation": "OshKosh, WI",
          "fieldAinEventDate": {
            "startDate": "2021-07-26 12:00:00 UTC",
            "endDate": "2021-08-01 12:00:00 UTC"
          },
          "fieldAinLink": {
            "uri": "http://www.eaa.org/en/airventure"
          }
        },
        {
          "entityLabel": "FlightSimExpo",
          "fieldAinEventLocation": "San Diego, CA",
          "fieldAinEventDate": {
            "startDate": "2021-09-24 12:00:00 UTC",
            "endDate": "2021-09-26 12:00:00 UTC"
          },
          "fieldAinLink": {
            "uri": "http://www.flightsimexpo.com/"
          }
        },
        {
          "entityLabel": "Sun 'n Fun",
          "fieldAinEventLocation": "Lakeland, FL",
          "fieldAinEventDate": {
            "startDate": "2020-03-31 12:00:00 UTC",
            "endDate": "2020-04-05 12:00:00 UTC"
          },
          "fieldAinLink": {
            "uri": "https://www.flysnf.org/"
          }
        }
      ]
    }
  }
}

I tried adding this, to no avail:

{operator: GREATER_THAN_OR_EQUAL, field: "fieldAinEventDate.startDate", value: ["2021-07-25 12:00:00 UTC"]}
Kevin avatar
in flag
It's not a date range or anything is it? Is "value" the right property?
hu flag
@Kevin see edit - and the error I get is just "Internal Server Error"
Kevin avatar
in flag
What is the logged error?
hu flag
Well I am running this in Drupal's GraphiQL Explorer, so all I have is Watchdog indicating "Call to a member function getColumns() on bool"
Kevin avatar
in flag
This sounds related: https://github.com/drupal-graphql/graphql/issues/710
Score:1
hu flag

Found the answer - apparently the fields are referenced differently in the filter conditions. This works:

{operator: GREATER_THAN_OR_EQUAL, field: "field_ain_event_date", value: ["2021-07-25 12:00:00 UTC"]}
Score:0
in flag

The important info here comes from a comment in the issue @Kevin referenced.

You can only query the fields available on the entity.

This is because your query is eventually converted to an entityQuery. You must reference fields and their properties as Drupal understands them, not how they're shown when returned from a GraphQL query.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.