Skip to content

Commit

Permalink
fix: Revert "fix: import graphql lazily (mswjs#2250)"
Browse files Browse the repository at this point in the history
This reverts commit 1799e06.
  • Loading branch information
grebenyuksv committed Sep 30, 2024
1 parent da28918 commit 7a2c6ff
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/core/utils/internal/parseGraphQLRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
OperationDefinitionNode,
OperationTypeNode,
} from 'graphql'
import { parse } from 'graphql'
import type { GraphQLVariables } from '../../handlers/GraphQLHandler'
import { toPublicUrl } from '../request/toPublicUrl'
import { devUtils } from './devUtils'
Expand Down Expand Up @@ -39,14 +40,7 @@ export function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery {
}
}

async function parseQuery(query: string): Promise<ParsedGraphQLQuery | Error> {
const { parse } = await import('graphql').catch((error) => {
devUtils.error(
'Failed to parse a GraphQL query: cannot import the "graphql" module. Please make sure you install it if you wish to intercept GraphQL requests. See the original import error below.',
)
throw error
})

function parseQuery(query: string): ParsedGraphQLQuery | Error {
try {
const ast = parse(query)
return parseDocumentNode(ast)
Expand Down Expand Up @@ -187,7 +181,7 @@ export async function parseGraphQLRequest(
}

const { query, variables } = input
const parsedResult = await parseQuery(query)
const parsedResult = parseQuery(query)

if (parsedResult instanceof Error) {
const requestPublicUrl = toPublicUrl(request.url)
Expand Down

0 comments on commit 7a2c6ff

Please sign in to comment.