Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/mswPublic

Commitca0e2e0

Browse files
authored
feat: make GraphQL a peer dependency, support GraphQL v15.0 (#1356)
* feat: move 'graphql' to peerDependencies. Add support for v15 of 'graphql'* feat: marking 'graphql' as an optional peer dependencyThe 'graphql' code that is needed at runtime will be dynamically loaded. Existing static imports of'graphql' are designated as type imports.
1 parent7fb1a32 commitca0e2e0

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

‎package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"chalk":"4.1.1",
7878
"chokidar":"^3.4.2",
7979
"cookie":"^0.4.2",
80-
"graphql":"^16.3.0",
8180
"headers-polyfill":"^3.0.4",
8281
"inquirer":"^8.2.0",
8382
"is-node-process":"^1.0.1",
@@ -116,6 +115,7 @@
116115
"eslint-plugin-prettier":"^3.4.0",
117116
"fs-extra":"^10.0.0",
118117
"fs-teardown":"^0.3.0",
118+
"graphql":"^16.3.0",
119119
"jest":"26",
120120
"json-bigint":"^1.0.0",
121121
"lint-staged":"^11.0.1",
@@ -134,9 +134,13 @@
134134
"webpack-dev-server":"^3.11.2"
135135
},
136136
"peerDependencies": {
137+
"graphql":"^15.0.0 || ^16.0.0",
137138
"typescript":">= 4.2.x <= 4.7.x"
138139
},
139140
"peerDependenciesMeta": {
141+
"graphql": {
142+
"optional":true
143+
},
140144
"typescript": {
141145
"optional":true
142146
}

‎src/context/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{GraphQLError}from'graphql'
1+
importtype{GraphQLError}from'graphql'
22
import{ResponseTransformer}from'../response'
33
import{jsonParse}from'../utils/internal/jsonParse'
44
import{mergeRight}from'../utils/internal/mergeRight'

‎src/graphql.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{DocumentNode,OperationTypeNode}from'graphql'
1+
importtype{DocumentNode,OperationTypeNode}from'graphql'
22
import{ResponseResolver}from'./handlers/RequestHandler'
33
import{
44
GraphQLHandler,
@@ -83,7 +83,7 @@ const standardGraphQLHandlers = {
8383
* })
8484
*@see {@link https://mswjs.io/docs/api/graphql/query `graphql.query()`}
8585
*/
86-
query:createScopedGraphQLHandler(OperationTypeNode.QUERY,'*'),
86+
query:createScopedGraphQLHandler('query'asOperationTypeNode,'*'),
8787

8888
/**
8989
* Captures a GraphQL mutation by a given name.
@@ -93,14 +93,14 @@ const standardGraphQLHandlers = {
9393
* })
9494
*@see {@link https://mswjs.io/docs/api/graphql/mutation `graphql.mutation()`}
9595
*/
96-
mutation:createScopedGraphQLHandler(OperationTypeNode.MUTATION,'*'),
96+
mutation:createScopedGraphQLHandler('mutation'asOperationTypeNode,'*'),
9797
}
9898

9999
functioncreateGraphQLLink(url:Path):typeofstandardGraphQLHandlers{
100100
return{
101101
operation:createGraphQLOperationHandler(url),
102-
query:createScopedGraphQLHandler(OperationTypeNode.QUERY,url),
103-
mutation:createScopedGraphQLHandler(OperationTypeNode.MUTATION,url),
102+
query:createScopedGraphQLHandler('query'asOperationTypeNode,url),
103+
mutation:createScopedGraphQLHandler('mutation'asOperationTypeNode,url),
104104
}
105105
}
106106

‎src/handlers/GraphQLHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{DocumentNode,OperationTypeNode}from'graphql'
1+
importtype{DocumentNode,OperationTypeNode}from'graphql'
22
import{SerializedResponse}from'../setupWorker/glossary'
33
import{data}from'../context/data'
44
import{extensions}from'../context/extensions'

‎src/utils/internal/parseGraphQLRequest.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import{
1+
importtype{
22
DocumentNode,
33
OperationDefinitionNode,
44
OperationTypeNode,
5-
parse,
65
}from'graphql'
76
import{GraphQLVariables}from'../../handlers/GraphQLHandler'
87
import{getPublicUrlFromRequest}from'../request/getPublicUrlFromRequest'
@@ -41,6 +40,9 @@ export function parseDocumentNode(node: DocumentNode): ParsedGraphQLQuery {
4140

4241
functionparseQuery(query:string):ParsedGraphQLQuery|Error{
4342
try{
43+
// Since 'graphql' is an optional peer dependency,
44+
// we'll attempt to import it dynamically
45+
const{ parse}=require('graphql')
4446
constast=parse(query)
4547
returnparseDocumentNode(ast)
4648
}catch(error){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp