1

I have this query but it's not getting called by MSW.

const response = (await API.graphql(graphqlOperation(listNotarys, { filter: filterInput }))) as {
    data: unknown;
  };

My handler looks like the following:

  graphql.query("ListNotarys", (req, res, ctx) =>
    res(
      ctx.data({
        data: {
          listNotarys: {
            items: [
              {
                id: "123",
                email: "email@gmail.com",
                name: "Name Here",
                phone: null,
                group: "GROUP_A",
                lastSigningDate: null,
                createdAt: "2021-11-12T14:06:57.492Z",
                updatedAt: "2021-11-12T14:32:07.190Z",
              },
            ],
            nextToken: null,
          },
        },
      }),
    ),
  ),

I have a setupTests.ts file that looks like this:

beforeAll(() => {
  awsAmplify.Auth.signIn.mockRejectedValue("mock error");
  awsAmplify.Auth.currentAuthenticatedUser.mockResolvedValue("mock user");
  server.listen({ onUnhandledRequest: "error" });
});
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

I get the following error when in my console:

An unhandled error occured processing a request for the endpoint "listNotarys". 
      In the case of an unhandled error, no tags will be "provided" or "invalidated". [TypeError: Cannot read property 'error' of undefined] 
  • 1
    What does "not getting handled" mean? Is it not getting called? Is it producing an error? Is it getting called but not appearing to do anything? Please explain better what you are expecting to happen and what you actually see happening. – Stephen Ostermiller Oct 15 '21 at 16:56
  • Please also list how you're using MSW (your request handlers, your test setup) and how you're making the actual GraphQL request. – kettanaito Nov 07 '21 at 00:56
  • Did you get mock-service-worker working with aws graphql queries like you wanted? I'm trying to do the same thing and would love some help! – Case Silva Oct 26 '22 at 19:34
  • Yeah I need an update as well if you got this to work! – klaurtar1 Jan 19 '23 at 21:20

0 Answers0