aboutsummaryrefslogtreecommitdiffstats
path: root/tests/msw/handlers/topics/topic.handler.ts
blob: 5df00ea7be0e2a14bbf15ebffcaec443e2da16ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { type ExecutionResult, graphql as executeGraphql } from 'graphql';
import { HttpResponse, graphql } from 'msw';
import type { TopicResponse } from '../../../../src/services/graphql';
import { wpTopicsFixture } from '../../../fixtures';
import { schema } from '../../schema';

export const topicHandler = graphql.query<
  TopicResponse,
  Record<'slug', string>
>('Topic', async ({ query, variables }) => {
  const { data, errors } = (await executeGraphql({
    schema,
    source: query,
    variableValues: variables,
    rootValue: {
      topic: wpTopicsFixture.find((wpTopic) => wpTopic.slug === variables.slug),
    },
  })) as ExecutionResult<TopicResponse>;

  return HttpResponse.json({ data, errors });
});