Error encountered while automatically updating the cache when creating a CompanyQuote component

Error encountered while automatically updating the cache when creating a CompanyQuote component


0

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,
      },
    });
  }
}

Share
Improve this question


Load 2 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *