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