Skip to content

Does MockedProvider behave differently from ApolloProvider? #8498

Open
@leonardoanalista

Description

@leonardoanalista

This is a question to start but it could become a bug or be closed, depending on the discussion here.

I am trying to use MockedProvider to test an error scenario with a custom code sent into the extensions. I noticed there is a different behavior going on between MockedProvider and ApolloProvider.

Does MockedProvider behave differently from real ApolloProvider for mutation promise chain?

  const [changePassword, { loading }] = useMutation(CHANGE_PASSWORD);

  const handleSubmit = (formValues) =>
    changePassword({
      variables: {
        input: {
          currentPassword: _.get(formValues, 'currentPassword'),
          newPassword: _.get(formValues, 'newPassword'),
        },
      },
    })
      .then((response) => {
         // This runs for MockedProvider, even when there is no data and there is an error.
         // This never runs for the real ApolloProvider when  is no data and there is an error.
      })
      .catch((error) => {
      });

Sample response:

{
   "errors":[
      {
         "message":"Invalid password",
         "locations":[... ],
         "path":[
            "changePassword"
         ],
         "extensions":{
            "code":"INVALID_PASSWORD_ERROR",
            "exception":{
               "stacktrace":[...]
            }
         }
      }
   ],
   "data":{
      "changePassword":null
   }
}

It seems like the execution of the changePassword mutation in the real app (ApolloProvider) throws an exception and jumps straight to the catch.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions