In a KeystoneJS GraphQL project I’m trying to create a new data object (an “Article”) in the ‘resolveInput’ hook of another, existing, data object (a “Proposal” — when a Proposal is approved, I create an Article based on that Proposals’data).
This worked fine using the Mongoose adapter, but I’ve tried to do it using the built in GraphQL API, using keystone.executeQuery
and I get the following error:
My Article list has a relationship with one Proposal (I’m leaving out the other fields)
fields: {
proposal: {
isUnique: false,
type: fields_1.Relationship,
ref: 'Proposal',
access: {
create: true,
read: true,
update: false
}
}
}
and I create the new Article thus (I’m omitting some code)
hooks: {
resolvedInput: async params => {
const articleCreateInput = {
title: cleanTitle,
text: cleanText,
visible: HIDDEN,
proposal: {
connect: {
id: proposalId
}
}
};
const articleCreationResult = await keystone.executeQuery(createArticle, { variables: articleCreateInput });
}
}
As far as I can see this is the correct way to do it, using connect, connecting an existing item to one you are creating.
My query is
const createArticle = `mutation createArticle($data:ArticleCreateInput) {
createArticle(data:$data) {
id
title
visible
publishDate
}
} `;
and as far as I can see I’m following the schema correctly
I’m sure I’m making an obvious mistake but at the moment I don’t see it — and I’m not sure whether that mistake is a GraphQL mistake or a KeystoneJS mistake (or both).
9
check query arguments (variables) – is
articleCreateInput
properly definedMar 25, 2020 at 23:19
It works fine from the playground…
Mar 26, 2020 at 8:36
… but in code … logged before
executeQuery
?Mar 26, 2020 at 9:17
@xadm It's
{ title: 'This is the new thing', text: 'abcdefh', visible: 'hidden', proposal: { connect: { id: '5e5e74c2ddd03b71b42281a8' } } }
Mar 26, 2020 at 9:53
relation? one to one?
Mar 26, 2020 at 9:56