blob: 3a71c8e9f520a9daad78f677354225994ae5ac91 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
import { HttpResponse, graphql } from 'msw';
import type { ThematicsSlugsResponse } from '../../../../src/services/graphql';
import { wpThematicsFixture } from '../../../fixtures';
import { schema } from '../../schema';
export const thematicsSlugsHandler = graphql.query<
ThematicsSlugsResponse,
Record<'first', number>
>('ThematicsSlugs', async ({ query, variables }) => {
const pageParams = new URLSearchParams(window.location.search);
const isError = pageParams.get('error') === 'true';
if (isError) return HttpResponse.json({ data: { thematics: null } });
const { data, errors } = (await executeGraphql({
schema,
source: query,
variableValues: variables,
rootValue: {
thematics: { nodes: wpThematicsFixture },
},
})) as ExecutionResult<ThematicsSlugsResponse>;
return HttpResponse.json({ data, errors });
});
|