获取单个文档,提供其 relativePath
作为参数。
relativePath
是相对于 collection
路径的部分路径。在这个例子中,post
集合的路径是 content/posts
,你的文档可以在 content/posts/voteForPedro.md
找到,给出 relativePath: "voteForPedro.md"
。如果你的项目在 content/posts/nested-folder/voteForPedro.md
,你需要指定:relativePath: "nested-folder/voteForPedro.md"
。
我们上面 schema 的集合命名为 "post" 和 "author",因此我们可以使用 post
和 author
查询每一个。
仅查询作者。
{author(relativePath: "napolean.json") {name}}
{"data": {"author": {"name": "Napolean"}}}
查询文章和作者。
{post(relativePath: "voteForPedro.json") {titlecategoryauthor {... on Author {name}}}}
{"data": {"post": {"title": "Vote For Pedro","category": "politics","author": {"name": "Napolean"}}}}
在作者上查询文章。
{author(relativePath: "napolean.json") {namepost {edges {node {title}}}}}
{"data": {"author": {"name": "Napolean","post": {"edges": ["node": {"title": "Vote for Pedro",}]}}}}
在一个集合中,有一些字段是所有文档共有的。这些字段是:id
,_values
和 _sys
。id
字段是文档的唯一标识符。_values
字段在编辑模式中内部使用,不用于外部。_sys
字段包含关于文档的元信息。
_sys
字段是一个包含以下字段的对象:
filename
: 文件名,不包括扩展名basename
: 文件名,包括扩展名path
: 文件相对于项目根目录的完整路径breadcrumbs
: 文件的父文件夹数组relativePath
: 文件相对于集合路径的路径extension
: 文件的扩展名template
: 文档的模板(如果不使用 templates
,则为集合的名称)collection
: 关于集合的信息{post(relativePath: "nested/anotherPost.json") {id_sys {filenamebasenamepathbreadcrumbsrelativePathextensiontemplate}}}
{"data": {"post": {"id": "content/posts/nested/anotherPost.json","_sys": {"filename": "anotherPost","basename": "anotherPost.json","path": "content/posts/nested/anotherPost.json","breadcrumbs": ["nested","anotherPost"],"relativePath": "nested/anotherPost.json","extension": ".json","template": "post"}}}}
{post(relativePath: "anotherPost.json") {id_sys {filenamebasenamepathbreadcrumbsrelativePathextensiontemplate}}}
{"data": {"post": {"id": "content/posts/anotherPost.json","_sys": {"filename": "anotherPost","basename": "anotherPost.json","path": "content/posts/anotherPost.json","breadcrumbs": ["anotherPost"],"relativePath": "anotherPost.json","extension": ".json","template": "post"}}}}