mswjs / examples

Examples of Mock Service Worker usage with various frameworks and libraries.
683 stars 211 forks source link

MSW with GrapqhQl fragments #80

Closed neemeeller closed 2 years ago

neemeeller commented 2 years ago

Hey, could you please guide me with the graphql query that is using fragments. Without fragments graphql queries are working fine and Mock Service Worker is serving results as expected.

But this one query is not using msw and is still making request to the actual api.

query FeaturesQuery($site: String!) {
  features {
    ...FeaturesFragment
  }
}

fragment FeaturesFragment on Features {
  __typename
  id
  automaticFeaturedEventsEnabled: isFlagActive(site: $site, name: "automaticFeaturedEvents")
  is2MeeEnabled: isFlagActive(site: $site, name: "is2MeeEnabled")
}

In msw handlers I've defined just

export const handlers = [
  graphql.query('FeaturesQuery', (_req, res, ctx) =>
    res(
      ctx.data({
        features: {
          __typename: 'Features',
          id: 'RmVhdHVyZXM6R0xPQkFMTFlfVU5JUVVFX0ZFQVRVUkVTX0lE',
          automaticFeaturedEventsEnabled: true,
          is2MeeEnabled: true,
        },
      })
    )
  ),
];

How should I tweak the query so that msw would understand it?