apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

v3.5.0+ ApolloClient.mutate() type error: Property 'errors' does not exist

Open harsh0596 opened this issue 3 years ago • 12 comments

call mutate using ApolloClient class:

let result = await client.mutate(...)

try to access errors:

console.log(result.errors)

error:

Property 'errors' does not exist on type 'FetchResult<any, Record<string, any>, Record<string, any>>'.

works on 3.4.0

harsh0596 avatar Jan 11 '22 16:01 harsh0596

Ran into the same issue while trying to upgrade.

l4j3b avatar Jan 14 '22 16:01 l4j3b

This is caused by having an incompatible version of the graphql package. Upgrading from 14 to 16.0.1 fixed this for me.

LeSphax avatar Mar 11 '22 20:03 LeSphax

+1

ErlanBelekov avatar Jun 10 '22 07:06 ErlanBelekov

@LeSphax didn't help in my case, still getting the error even on "graphql": "16.0.1"

ErlanBelekov avatar Jun 10 '22 07:06 ErlanBelekov

👋 Hello everyone! Would you be willing to upgrade to v3.6.7 and let us know if you are still seeing this problem?

jpvajda avatar Jun 10 '22 21:06 jpvajda

@jpvajda the issue is still there at v3.6.9 Property 'errors' does not exist on type 'FetchResult<MyMutation, Record<string, any>, Record<string, any>>'

Code:

const res = await replyToDealVerificationRequest({
      variables: {
        input: {
          dealID,
          isVerified: false,
          ...({ description } || {}),
        },
      },
    })

    if (res.errors && res.errors.length) {
      toast({
        title: 'Rejection failed',
        description: String((res as any).errors[0].message),
      })
    }

Relevant dependencies(with dev ones):

"@apollo/client": "^3.6.9",
"@apollo/link-context": "^2.0.0-beta.3",
"apollo-upload-client": "^17.0.0",
"graphql": "^15.5.0",
"@graphql-codegen/cli": "^1.21.5",
"@graphql-codegen/typescript": "^1.22.1",
"@graphql-codegen/typescript-operations": "^1.18.0",
"@graphql-codegen/typescript-react-apollo": "^2.2.5",
"@types/apollo-upload-client": "^17.0.0",

ErlanBelekov avatar Jul 19 '22 07:07 ErlanBelekov

ran into the same issue as @ErlanBelekov just upgraded to 3.6.9

trevorglick avatar Aug 18 '22 23:08 trevorglick

Still running into this issue on @apollo/client version 3.7.3 with graphql version 16.6.0

collinsrs avatar Jan 12 '23 02:01 collinsrs

for me it worked again after upgrading to graphql:16.6.0 & @apollo/client: 3.7.7

ludwigkaube avatar Feb 13 '23 14:02 ludwigkaube

I'm experiencing this, too. I tried upgrading to [email protected] and @apollo/[email protected] and was still seeing this problem. But explicitly defining the type as SingleExecutionResult (imported from @apollo/client) seems to fix the problem.

// Must explicitly type to appease TS - for some reason the FetchResult type union isn't
// resolving to the proper subtype.
//
// See: https://github.com/apollographql/apollo-client/issues/9292
const results: SingleExecutionResult[] = await Promise.all(promises);

Would be curious to know if this workaround works for anyone else.

cmslewis avatar Feb 18 '23 08:02 cmslewis

same problem here with client 3.8.8 and graphql 16.8.1

rbmdotdev avatar Feb 14 '24 20:02 rbmdotdev

Could you create some kind of reproduction for this?

If you try this TypeScript playground, it's there.

(Screenshot shows 3.9.4) image

Same for versions 3.5.0 image

and version 3.8.8 image

phryneas avatar Feb 15 '24 07:02 phryneas