Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Graphql MockServer Resolver Preservation #253

@cchen9299

Description

@cchen9299

Motivation:
With the introduction of parrot-friendly@5.0.0 and parrot-graphql@5.0.0, the underlying @graphql-tools/mock went from v2 to v8. Through this change, mocked resolver behaviors changed and for our teams, specifically the ability to key into request information to return corresponding mock data.

To elaborate, given there is a feature where the UI displays email information of multiple users and there is an operation that fetches user's email. The UI can either be making aliased calls or multiple calls to graphql with the user's ID expecting that the corresponding data is returned for each user ID. Previously we were able to mock the resolver dynamically with the first argument in the mocked resolver. But with graphql-toolsV8 by default, those resolvers are seemingly flattened and no longer provide the request information.

const { graphql } = require('parrot-friendly')
const { getUserEmail } = require('./helper');

...

it('US - CARD & BANKING (multi) - Mobile Phone - security update failure', () => {
  graphql('/graphql', schema, {
    Query: () => ({
      // resolver args are now undefine
      getEmail: ({ userID }) => getUserEmail(userID),
    }),
  });
});

The only solution that I've found so far is to update the preserveResolver value to true (the third argument passed to mockServer of @graphql-tools/mock). I am then able to pass in makeExecutableSchema({}) of the basically the same resolver to see the request information again. (Basically the same because graphql-tools have since move the request variable to the second argument ie., getEmail: (_, { userID }) => getUserEmail(userID),)

Will be opening a PR for this for review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions