-
Notifications
You must be signed in to change notification settings - Fork 57
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
Graphql 17 support #185
Graphql 17 support #185
Changes from 10 commits
63f8b64
2a0407c
83ae6f5
07dfe5e
9cff6e1
887937c
f27a194
aae9d94
c68180a
4133630
436f6d5
ffb1ae0
f3a70c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,18 +39,18 @@ | |
}, | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 92, | ||
"branches": 91, | ||
"functions": 96, | ||
"lines": 96, | ||
"statements": 96 | ||
} | ||
} | ||
}, | ||
"peerDependencies": { | ||
"graphql": ">=15" | ||
"graphql": ">=17" | ||
}, | ||
"devDependencies": { | ||
"@graphql-tools/schema": "^8.3.1", | ||
"@graphql-tools/schema": "^9.0.8", | ||
"@stryker-mutator/core": "^2.0.0", | ||
"@stryker-mutator/jest-runner": "^2.0.0", | ||
"@stryker-mutator/typescript": "^2.0.0", | ||
|
@@ -72,7 +72,7 @@ | |
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.1", | ||
"eslint-plugin-standard": "^5.0.0", | ||
"graphql": "^16.0.0", | ||
"graphql": "^17.0.0-alpha.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be also changed back to 16 before merging, as 17 is nevertheless still alpha. We will keep support in test runs, though. |
||
"jest": "^27.4.3", | ||
"lint-staged": "^8.1.5", | ||
"prettier": "^2.4.1", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import * as GraphQL from "graphql"; | ||
import { GraphQLSchema, versionInfo } from "graphql"; | ||
import * as utilities from "graphql/utilities"; | ||
import { GraphQLObjectType } from "graphql/type/definition"; | ||
import { OperationDefinitionNode } from "graphql/language/ast"; | ||
|
||
/** | ||
* A helper to support backward compatibility for different versions of graphql-js. | ||
|
@@ -14,14 +17,20 @@ import * as GraphQL from "graphql"; | |
* | ||
* GraphQL v17 would remove getOperationRootType. | ||
*/ | ||
export function getOperationRootType( | ||
schema: GraphQL.GraphQLSchema, | ||
operation: GraphQL.OperationDefinitionNode | ||
) { | ||
if (GraphQL.getOperationRootType) { | ||
return GraphQL.getOperationRootType(schema, operation); | ||
} else { | ||
// the use of any is to support graphql v15 types which will not use this codepath | ||
return (schema as any).getRootType(operation.operation)!; | ||
|
||
export const getOperationRootType = ( | ||
schema: GraphQLSchema, | ||
operation: OperationDefinitionNode | ||
): GraphQLObjectType => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please refactor this arrow function expression to function declaration. |
||
if (versionInfo.major < 16) { | ||
return (utilities as any).getOperationRootType(schema, operation); | ||
} | ||
} | ||
|
||
const type = (schema as any).getRootType(operation.operation); | ||
|
||
if (!type) { | ||
throw new Error(`No root type for operation ${operation.operation}`); | ||
} | ||
|
||
return type; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { GraphQLError, versionInfo } from "graphql"; | ||
import * as utilities from "graphql/error"; | ||
import { GraphQLFormattedError } from "graphql/error"; | ||
|
||
export const formatError = (error: GraphQLError): GraphQLFormattedError => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please refactor to function declaration instead of using arrow function expression. |
||
if (versionInfo.major < 16) { | ||
return (utilities as any).formatError(error); | ||
} | ||
|
||
return (error as any).toJSON(); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Maybe } from "graphql/jsutils/Maybe"; | ||
import { ASTNode } from "graphql/language/ast"; | ||
import { GraphQLError, versionInfo } from "graphql"; | ||
|
||
export const getGraphQLErrorOptions = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this to the |
||
nodes: Maybe<ReadonlyArray<ASTNode> | ASTNode> | ||
): ConstructorParameters<typeof GraphQLError>[1] => { | ||
if (versionInfo.major < 16) { | ||
return nodes as any; | ||
} | ||
|
||
return { nodes } as any; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This we should keep as
>=15
for now, as we still support 15