Contentful GraphQL 端点:如何检索内容类型的所有条目

Luc*_*cia 3 contentful graphql

{
  Post {
      name
  }
}
Run Code Online (Sandbox Code Playgroud)

在尝试检索内容类型上的所有条目时,它仅给出以下错误:

"Argument \"id\" of required type \"String!\" was not provided."
Run Code Online (Sandbox Code Playgroud)

由于id需要字段。那么如何获取某个内容类型的所有条目呢?

参考:https: //www.contentful.com/developers/docs/references/graphql/

Luc*_*cia 5

从这里的文档:

生成的 Query 对象公开两个可用于查询该类型内容的字段:一个用于获取单个内容文档(friendlyUser在示例中),另一个用于对该类型的所有内容进行查询 ( friendlyUserCollection)。

因此,对于任何想要检索其所有条目的资源,您需要Collection在其 id 末尾附加,然后使用itemsfield 来检索所有条目。如:

{
  PostCollection {
      items {
          name
      }
  }
}
Run Code Online (Sandbox Code Playgroud)

除了文档之外,您还可以在此处查看相应 GraphiQL 实例的所有可用资源,这可能非常有用:

https://graphql.contentful.com/content/v1/spaces/{SPACE_ID}/explore?access_token={ACCESS_TOKEN}

搜索或选择Query查看所有架构:

GraphiQL