I’m working on a project where I’ve created a backend script to handle GraphQL requests. I have a file called company.graphql
that contains a query to retrieve information about a company and its related quotes. Here’s a snippet of the script
query Companie($id: String!) {
companie(id: $id) {
attachmentId
companieQuotes {
attachmentId
}
}
}
client.js:1 Missing field ‘attachmentId’ while writing result {
“attachmentId”: 13,
“__typename”: “COMPANIEQUOTE”
}
if (response.data.createCompanieQuote.errors) {
....
} else if (response.data.createCompanieQuote.companieQuote.attachmentId) {
const updatedData = client.cache.readQuery<CompanieQuery>({
query: CompanieDocument,
variables: {
id: router.query.companieId as string,
},
});
if (updatedData.companie) {
const newCompanieQuote =
response.data.createCompanieQuote.companieQuote;
const updatedCompanie = {
...updatedData.companie,
companieQuotes: [
...updatedData.companie.companieQuotes,
newCompanieQuote,
],
};
client.cache.writeQuery({
query: CompanieDocument,
variables: {
id: router.query.companieId as string,
},
data: {
companie: updatedCompanie,
},
});
}
}