Get a single document, providing it's relativePath
as the argument.
relativePath
is the portion of the path relative to the collection
's path.In this example, the post
collection has a path of content/posts
and your document can be found at content/posts/voteForPedro.md
giving relativePath: "voteForPedro.md"
. If your item was at content/posts/nested-folder/voteForPedro.md
you'd specify: relativePath: "nested-folder/voteForPedro.md"
.
Our collections for the above schema are named "post" and "author", so we can query for each using the post
& author
Query on author only.
{author(relativePath: "napolean.json") {name}}
{"data": {"author": {"name": "Napolean"}}}
Query on post and author.
{post(relativePath: "voteForPedro.json") {titlecategoryauthor {... on Author {name}}}}
{"data": {"post": {"title": "Vote For Pedro","category": "politics","author": {"name": "Napolean"}}}}
In a collection, there are a few fields that are common to all documents. These are: id
, _values
and _sys
. The id
field is a unique identifier for the document. The _values
field is used internally in edit mode and is not for external use. The _sys
field contains meta information about the document.
The _sys
field is an object with the following fields:
filename
: The name of the file without the extensionbasename
: The name of the file with the extensionpath
: The full path of the file relative to the project rootbreadcrumbs
: An array of the parent folders of the filerelativePath
: The path of the file relative to the collection pathextension
: The extension of the filetemplate
: The template of the document (or the name of the collection if not using templates
)collection
: Information about the 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"}}}}
Last Edited: August 15, 2024
© TinaCMS 2019–2024