keystone
keystone copied to clipboard
Documentation for example GQL query to create list item with document field
I'm trying to write some GQL to create some posts for my test Keystone install, and I'm unsure what I'm doing wrong in relation to the document field. I'm getting a strange error back even for the simplest data.
For example, with my Post type which looks like this
export default list({
access: {
operation: {
}
},
fields: {
title: text({ validation: { isRequired: true } }),
status: select({
type: 'enum',
options: [
{ label: 'Draft', value: 'draft' },
{ label: 'Published', value: 'published' },
],
}),
content: document({
formatting: true
}),
headerImage: image(),
publishDate: timestamp(),
author: relationship({ ref: 'Author.posts', many: false }),
gameId: json({
ui: {
views: // Some plugin
}
}),
youtubeId: json({
ui: {
views: // Some plugin
}
})
},
})
And my GQL which looks like the following
mutation {
createPost(data: {
title:"Some Thing"
content:[
{
type: "paragraph",
children: [{ text: "adadasadasad" }]
}
]
}){
id
}
}
I'm getting the following error
{
"errors": [
{
"message": "An error occured while resolving input fields.\n - Post.content: Cannot read properties of undefined (reading 'map')",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"createPost"
],
"extensions": {
"debug": [
{
"stacktrace": "TypeError: Cannot read properties of undefined (reading 'map')\n at getValidatedNodeWithNormalizedComponentFormProps (<<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:334:29)\n at <<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:334:38\n at Array.map (<anonymous>)\n at getValidatedNodeWithNormalizedComponentFormProps (<<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:334:29)\n at <<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:339:35\n at Array.map (<anonymous>)\n at validateAndNormalizeDocument (<<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:339:26)\n at inputResolver (<<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:553:14)\n at Object.resolve (<<project-Path>>\\node_modules\\@keystone-next\\fields-document\\dist\\keystone-next-fields-document.cjs.dev.js:577:20)\n at resolve (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\json-field-type-polyfill-for-sqlite-dafd9fc6.cjs.dev.js:162:75)",
"message": "Cannot read properties of undefined (reading 'map')"
}
],
"code": "KS_RESOLVER_ERROR",
"exception": {
"stacktrace": [
"Error: An error occured while resolving input fields.",
" - Post.content: Cannot read properties of undefined (reading 'map')",
" at Object.resolverError (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\graphql-errors-333c98d2.cjs.dev.js:54:10)",
" at getResolvedData (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\initConfig-5302ef8e.cjs.dev.js:1823:25)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at resolveInputForCreateOrUpdate (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\initConfig-5302ef8e.cjs.dev.js:1951:27)",
" at createSingle (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\initConfig-5302ef8e.cjs.dev.js:1657:7)",
" at createOne (<<project-Path>>\\node_modules\\@keystone-next\\keystone\\dist\\initConfig-5302ef8e.cjs.dev.js:1718:7)"
]
}
}
}
],
"data": {
"createPost": null
}
}
I have also tried with a document field under the content field, but that failed the validation step. Is there an example of this in the docs that I'm missing? Is there something I'm missing in the GQL?
Extra information
The above GQL is failing because the { text: "adadasadasad" } part of the JSON is failing the isText() check of the getValidatedNodeWithNormalizedComponentFormProps().
Am I missing something?