Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert the lazy import of graphql #2298

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions config/plugins/esbuild/graphQLImportPlugin.ts

This file was deleted.

14 changes: 3 additions & 11 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,16 +40,7 @@ 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')

function parseQuery(query: string): ParsedGraphQLQuery | Error {
try {
const ast = parse(query)
return parseDocumentNode(ast)
Expand Down Expand Up @@ -189,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
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
Loading