Reputation: 13571
{
Post {
name
}
}
While trying to retrieve all the entries on a content type, it only gives error of:
"Argument \"id\" of required type \"String!\" was not provided."
Since id
field is required. How do I get all entries of a content type then?
Ref: https://www.contentful.com/developers/docs/references/graphql/
Upvotes: 3
Views: 7187
Reputation: 4216
Having agreed that the right way to filter Post's is to query for a PostCollection, there are a few parameters that may come handy:
{
PostCollection(limit: 30) {
items {
name
text
}
}
}
Having an idea of the size of the collection, this one limits the back-end resources that the query will allocate. By default the size is 100 and if the collection contains only a few elements, not specifying the limit is a waste of resources.
{
PostCollection(where: { topic: "politics" }) {
items {
name
text
}
}
}
This one will retrieve only the posts with a certain topic field (obviously, the field must be present in the content type and be filled in the contents).
There are a lot of other possibilities.
Upvotes: 0
Reputation: 1949
id
I think you can try this in the GraphQL playgound
http://localhost:8000/___graphql
query PostById($id: String!) {
contentfulPost(id: { eq: $id }) {
name
}
}
and add a QUERY VARIABLE
{
"id": "my-awesome-id"
}
Posts
How do I get all entries of a content type then?
As already mentioned in the accepter answer, in the GraphQL playground app, you shall be able to do the following:
{
PostCollection {
items {
name
}
}
}
Upvotes: -1
Reputation: 13571
From docs here:
The produced Query object exposes two fields that you can use to query content of that type: one to fetch individual content documents (
friendlyUser
in the example) and another to do queries over all the content of the type (friendlyUserCollection
).
So for any resource that you want to retrieve all entries of, you need to append Collection
at the end of its id, then use items
field to retrieve all entries. As in:
{
PostCollection {
items {
name
}
}
}
Apart from docs, you can also view all available resources at corresponding GraphiQL instance here, which could be pretty useful:
https://graphql.contentful.com/content/v1/spaces/{SPACE_ID}/explore?access_token={ACCESS_TOKEN}
Search or select Query
to see all schemas:
Upvotes: 6