diff --git a/package.json b/package.json index fe820a07d..ceb5ed002 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "chalk": "4.1.1", "chokidar": "^3.4.2", "cookie": "^0.4.2", + "graphql": "^15.0.0 || ^16.0.0", "headers-polyfill": "^3.0.4", "inquirer": "^8.2.0", "is-node-process": "^1.0.1", @@ -115,7 +116,6 @@ "eslint-plugin-prettier": "^3.4.0", "fs-extra": "^10.0.0", "fs-teardown": "^0.3.0", - "graphql": "^16.3.0", "jest": "26", "json-bigint": "^1.0.0", "lint-staged": "^11.0.1", @@ -134,13 +134,9 @@ "webpack-dev-server": "^3.11.2" }, "peerDependencies": { - "graphql": "^15.0.0 || ^16.0.0", "typescript": ">= 4.2.x <= 4.8.x" }, "peerDependenciesMeta": { - "graphql": { - "optional": true - }, "typescript": { "optional": true } @@ -153,4 +149,4 @@ "path": "./node_modules/cz-conventional-changelog" } } -} \ No newline at end of file +} diff --git a/src/utils/internal/parseGraphQLRequest.ts b/src/utils/internal/parseGraphQLRequest.ts index 83835334c..b3d757040 100644 --- a/src/utils/internal/parseGraphQLRequest.ts +++ b/src/utils/internal/parseGraphQLRequest.ts @@ -3,6 +3,7 @@ import type { OperationDefinitionNode, OperationTypeNode, } from 'graphql' +import { parse } from 'graphql' import { GraphQLVariables } from '../../handlers/GraphQLHandler' import { getPublicUrlFromRequest } from '../request/getPublicUrlFromRequest' import { MockedRequest } from '../request/MockedRequest' @@ -40,9 +41,6 @@ export function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery { function parseQuery(query: string): ParsedGraphQLQuery | Error { try { - // Since 'graphql' is an optional peer dependency, - // we'll attempt to import it dynamically - const { parse } = require('graphql') const ast = parse(query) return parseDocumentNode(ast) } catch (error) { diff --git a/test/graphql-api/compatibility.node.test.ts b/test/graphql-api/compatibility.node.test.ts index 62fdf7ac2..c317e6d81 100644 --- a/test/graphql-api/compatibility.node.test.ts +++ b/test/graphql-api/compatibility.node.test.ts @@ -1,6 +1,5 @@ import fetch from 'cross-fetch' -import { graphql as executeGraphql } from 'graphql' -import { buildSchema } from 'graphql/utilities' +import { graphql as executeGraphql, buildSchema } from 'graphql' import { graphql } from 'msw' import { setupServer } from 'msw/node' import { createGraphQLClient, gql } from '../support/graphql' diff --git a/test/graphql-api/extensions.node.test.ts b/test/graphql-api/extensions.node.test.ts index d8bef7b3c..918294795 100644 --- a/test/graphql-api/extensions.node.test.ts +++ b/test/graphql-api/extensions.node.test.ts @@ -1,14 +1,11 @@ /** * @jest-environment node */ -import fetch from 'node-fetch' -import { - graphql as executeGraphql, - buildSchema, - ExecutionResult, -} from 'graphql' +import type { ExecutionResult } from 'graphql' +import { buildSchema, graphql as executeGraphql } from 'graphql' import { graphql } from 'msw' import { setupServer } from 'msw/node' +import fetch from 'node-fetch' import { gql } from '../support/graphql' const schema = gql` diff --git a/test/graphql-api/extensions.test.ts b/test/graphql-api/extensions.test.ts index 8510ae93a..a65d9abfe 100644 --- a/test/graphql-api/extensions.test.ts +++ b/test/graphql-api/extensions.test.ts @@ -1,6 +1,6 @@ import * as path from 'path' import { pageWith } from 'page-with' -import { ExecutionResult } from 'graphql' +import type { ExecutionResult } from 'graphql' import { executeGraphQLQuery } from './utils/executeGraphQLQuery' import { gql } from '../support/graphql' diff --git a/test/graphql-api/response-patching.node.test.ts b/test/graphql-api/response-patching.node.test.ts index 04e7b6cb3..ad7967b3a 100644 --- a/test/graphql-api/response-patching.node.test.ts +++ b/test/graphql-api/response-patching.node.test.ts @@ -4,8 +4,7 @@ import { graphql } from 'msw' import { setupServer } from 'msw/node' import fetch from 'cross-fetch' -import { graphql as executeGraphql } from 'graphql' -import { buildSchema } from 'graphql/utilities' +import { graphql as executeGraphql, buildSchema } from 'graphql' import { ServerApi, createServer } from '@open-draft/test-server' import { createGraphQLClient, gql } from '../support/graphql' diff --git a/test/graphql-api/response-patching.test.ts b/test/graphql-api/response-patching.test.ts index a003c4d7d..83074f7a5 100644 --- a/test/graphql-api/response-patching.test.ts +++ b/test/graphql-api/response-patching.test.ts @@ -1,6 +1,7 @@ import * as path from 'path' import { pageWith } from 'page-with' -import { ExecutionResult, buildSchema, graphql } from 'graphql' +import type { ExecutionResult } from 'graphql' +import { buildSchema, graphql } from 'graphql' import { ServerApi, createServer } from '@open-draft/test-server' import { SetupWorkerApi } from 'msw' import { gql } from '../support/graphql' diff --git a/test/support/graphql.ts b/test/support/graphql.ts index 12b2d2145..766e47c5d 100644 --- a/test/support/graphql.ts +++ b/test/support/graphql.ts @@ -1,4 +1,4 @@ -import { ExecutionResult } from 'graphql' +import type { ExecutionResult } from 'graphql' /** * Identity function that returns a given template string array. diff --git a/yarn.lock b/yarn.lock index 25fdaf88a..744375edb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5345,10 +5345,10 @@ graceful-fs@^4.2.9: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== -graphql@^16.3.0: - version "16.3.0" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.3.0.tgz#a91e24d10babf9e60c706919bb182b53ccdffc05" - integrity sha512-xm+ANmA16BzCT5pLjuXySbQVFwH3oJctUVdy81w1sV0vBU0KgDdBGtxQOUd5zqOBk/JayAFeG8Dlmeq74rjm/A== +"graphql@^15.0.0 || ^16.0.0": + version "16.6.0" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.6.0.tgz#c2dcffa4649db149f6282af726c8c83f1c7c5fdb" + integrity sha512-KPIBPDlW7NxrbT/eh4qPXz5FiFdL5UbaA0XUNz2Rp3Z3hqBSkbj0GVjwFDztsWVauZUWsbKHgMg++sk8UX0bkw== growly@^1.3.0: version "1.3.0"