Back

Returning specific attributes with GraphQL

  • 0
  • GraphQL
  • Cloud
will_speaks
26 Jul, 2024, 15:18

I'm trying to use the GraphQL API to return a single attribute along with the _id, rather than the entire document. According to the documentation, the following should work:

query { databasesListDocuments( databaseId: "${DATABASE_ID}", collectionId: "${COLLECTION_ID}" ) { total documents { _id data { attribute1 } } } }

However, I'm getting the following error:

Response: {"errors":[{"message":"Field data of type String must not have a sub selection.","extensions":{"category":"graphql"},"locations":[{"line":9,"column":16}]}]}

The following doesn't work either:

query { databasesListDocuments( databaseId: "${DATABASE_ID}", collectionId: "${COLLECTION_ID}" ) { total documents { _id attribute1 } } }

Any ideas what I'm doing wrong?

TL;DR
Developers are trying to return a specific attribute with the GraphQL API along with the _id but are encountering an error. The error is due to trying to include a subselection for a scalar field. To fix this, switch the query to directly access the desired attribute like so: `query { databasesListDocuments( databaseId: "${DATABASE_ID}", collectionId: "${COLLECTION_ID}" ) { total documents { _id attribute1 } } }`
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more