GraphQL how to check if a field exists

1k Views Asked by At

How can I make a query and check if a field exists in graphql?

I have e.g. tried with the following query:

query MyQuery($slug: String!) {
   page(filter: {slug: {eq: $slug}}) {
     ... on PageRecord {
       qaBlock {
         items {
           header
           content
         }
       title
      }
    }
  }
}

so my issue is, that as soon I hit a page, where the QA block doesn't exist, the page breaks and I get an error Field 'qaBlock' doesn't exist on type 'PageRecord'

is there a way to solve this? My desired output would be something like:

{
  qaBlock: null /// or just []
}
0

There are 0 best solutions below