diff options
Diffstat (limited to 'tests/msw/handlers/posts/post.handler.ts')
| -rw-r--r-- | tests/msw/handlers/posts/post.handler.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/msw/handlers/posts/post.handler.ts b/tests/msw/handlers/posts/post.handler.ts new file mode 100644 index 0000000..4abdfed --- /dev/null +++ b/tests/msw/handlers/posts/post.handler.ts @@ -0,0 +1,21 @@ +import { type ExecutionResult, graphql as executeGraphql } from 'graphql'; +import { HttpResponse, graphql } from 'msw'; +import type { PostResponse } from '../../../../src/services/graphql'; +import { wpPostsFixture } from '../../../fixtures'; +import { schema } from '../../schema'; + +export const postHandler = graphql.query<PostResponse, Record<'slug', string>>( + 'Post', + async ({ query, variables }) => { + const { data, errors } = (await executeGraphql({ + schema, + source: query, + variableValues: variables, + rootValue: { + post: wpPostsFixture.find((wpPost) => wpPost.slug === variables.slug), + }, + })) as ExecutionResult<PostResponse>; + + return HttpResponse.json({ data, errors }); + } +); |
