Skip to content

Commit

Permalink
fix: Revert "fix: keep graphql import as require in cjs (mswjs#2258)"
Browse files Browse the repository at this point in the history
This reverts commit b977602.
  • Loading branch information
grebenyuksv committed Sep 30, 2024
1 parent 452686d commit da28918
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 44 deletions.
34 changes: 0 additions & 34 deletions config/plugins/esbuild/graphQLImportPlugin.ts

This file was deleted.

14 changes: 6 additions & 8 deletions src/core/utils/internal/parseGraphQLRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ export function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery {
}

async function parseQuery(query: string): Promise<ParsedGraphQLQuery | Error> {
/**
* @note Use `require` to get the "graphql" module here.
* It has to be scoped to this function because this module leaks to the
* root export. It has to be `require` because tools like Jest have trouble
* handling dynamic imports. It gets replaced with a dynamic import on build time.
*/
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { parse } = require('graphql')
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
})

try {
const ast = parse(query)
Expand Down
3 changes: 1 addition & 2 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from './config/plugins/esbuild/copyWorkerPlugin'
import { resolveCoreImportsPlugin } from './config/plugins/esbuild/resolveCoreImportsPlugin'
import { forceEsmExtensionsPlugin } from './config/plugins/esbuild/forceEsmExtensionsPlugin'
import { graphqlImportPlugin } from './config/plugins/esbuild/graphQLImportPlugin'
import packageJson from './package.json'

// Externalize the in-house dependencies so that the user
Expand All @@ -34,7 +33,7 @@ const coreConfig: Options = {
sourcemap: true,
dts: true,
tsconfig: path.resolve(__dirname, 'src/tsconfig.core.build.json'),
esbuildPlugins: [graphqlImportPlugin(), forceEsmExtensionsPlugin()],
esbuildPlugins: [forceEsmExtensionsPlugin()],
}

const nodeConfig: Options = {
Expand Down

0 comments on commit da28918

Please sign in to comment.