'AWS Amplify - How to query GraphQL when some of the data is undefined

When using the AWS AppSync console, I can run this query and get a return...

  listAccounts {
    items {
      name
      cameras {
        items {
          name
        }
      }
    }
  }
}

But when I run the same query from inside my react app using

await API.graphql({ query: queries.listAccounts })

I get an error...

"Validation error of type FieldUndefined: Field 'items' in type 'Query' is undefined @ 'items'"

My issue is that an Account will not always have a camera, in which case I would like to be able to get the response and still display the camera data. Can anyone help me out here. Is there some way to 'allow' undefined?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source