Cms: GraphQL: How get a single element?

Created on 19 Dec 2019  路  2Comments  路  Source: craftcms/cms

Description

I want a single element/entry from the GraphQL-API instead of a list. How do I get it?
This would be possible in craft templates via one (): https://docs.craftcms.com/v3/dev/element-queries/#one

Example Query:

query getProduct($slug: [String]!) {
    product: entries(section: "products", slug: $slug) {
      id    
    }
  }

Response:
javascript{ "data": { "product": [ { "id": "8" } ] } }

  • Craft Version: Craft CMS 3.4.0-beta.4

Thanks

graphql

Most helpful comment

Yeah, okay. We'll add that for 3.4, but that'll be an entry query, as opposed to entries.

All 2 comments

Yeah, okay. We'll add that for 3.4, but that'll be an entry query, as opposed to entries.

Just pushed this for the next Craft 3.4 release. You can now use the singular forms of the queries (entries -> entry) to return a single result.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RitterKnightCreative picture RitterKnightCreative  路  3Comments

darylknight picture darylknight  路  3Comments

angrybrad picture angrybrad  路  3Comments

davist11 picture davist11  路  3Comments

timkelty picture timkelty  路  3Comments