-
-
Notifications
You must be signed in to change notification settings - Fork 833
feat(executor): add schema coordinates extension to graphql errors #7588
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
base: master
Are you sure you want to change the base?
Changes from all commits
c7fe7e1
0afeadd
b13cdea
c86f829
78dd816
4f4405b
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ASTNode, GraphQLError, Source, versionInfo } from 'graphql'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { locatedError as _locatedError, ASTNode, GraphQLError, Source, versionInfo } from 'graphql'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Maybe } from './types.js'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface GraphQLErrorOptions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -60,16 +60,50 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type SchemaCoordinateInfo = { fieldName: string; parentType: { name: string } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const ERROR_EXTENSION_SCHEMA_COORDINATE = Symbol.for('graphql.error.schemaCoordinate'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function addSchemaCoordinateToError(error: GraphQLError, info: SchemaCoordinateInfo): void { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // @ts-expect-error extensions can't be Symbol in official GraphQL Error type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error.extensions[ERROR_EXTENSION_SCHEMA_COORDINATE] = `${info.parentType.name}.${info.fieldName}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function locatedError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rawError: unknown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodes: ASTNode | ReadonlyArray<ASTNode> | null | undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: Maybe<ReadonlyArray<string | number>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info: SchemaCoordinateInfo | false | null | undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const error = _locatedError(rawError, nodes, path); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 76 in packages/utils/src/errors.ts
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (info) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addSchemaCoordinateToError(error, info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+70
to
+83
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. Fix type incompatibility with GraphQL's locatedError. The Apply this diff to fix the type: export function locatedError(
rawError: unknown,
- nodes: ASTNode | ReadonlyArray<ASTNode> | null | undefined,
+ nodes: ASTNode | ReadonlyArray<ASTNode> | undefined,
path: Maybe<ReadonlyArray<string | number>>,
info: SchemaCoordinateInfo | false | null | undefined,
) {
const error = _locatedError(rawError, nodes, path);📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: Type Check on GraphQL v15[failure] 76-76: 🪛 GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v15[failure] 76-76: 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function relocatedError( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originalError: GraphQLError, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path?: ReadonlyArray<string | number>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| info?: SchemaCoordinateInfo | false | null | undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): GraphQLError { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return createGraphQLError(originalError.message, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const error = createGraphQLError(originalError.message, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodes: originalError.nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source: originalError.source, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| positions: originalError.positions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path: path == null ? originalError.path : path, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| originalError, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extensions: originalError.extensions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extensions: info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...originalError.extensions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| schemaCoordinates: `${info.parentType.name}.${info.fieldName}`, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
EmrysMyrddin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : originalError.extensions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (info) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| addSchemaCoordinateToError(error, info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Fix incorrect import path causing build failures.
The import is trying to load from a non-existent file
'./locatedError.js'. ThelocatedErrorfunction is actually exported from'@graphql-tools/utils', which is already imported at the top of this file.Apply this diff:
-import { locatedError } from './locatedError.js';And add
locatedErrorto the existing import from'@graphql-tools/utils'at line 30-53:import { collectSubFields as _collectSubfields, addPath, collectFields, createGraphQLError, fakePromise, getArgumentValues, getDefinedRootType, GraphQLResolveInfo, GraphQLStreamDirective, inspect, isAsyncIterable, isIterableObject, isObjectLike, isPromise, + locatedError, mapAsyncIterator, Maybe, MaybePromise, memoize1, memoize3, Path, pathToArray, promiseReduce, } from '@graphql-tools/utils';📝 Committable suggestion
🧰 Tools
🪛 GitHub Actions: pr
[error] 60-60: TS2307: Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Actions: website
[error] 60-60: Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: alpha / snapshot
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: deployment
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Full Check on GraphQL v16
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Type Check on GraphQL v15
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Unit Test on Bun
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v15
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Unit Test on Node 18 (ubuntu-latest) and GraphQL v16
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Unit Test on Node 22 (ubuntu-latest) and GraphQL v16
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🪛 GitHub Check: Unit Test on Node 24 (ubuntu-latest) and GraphQL v16
[failure] 60-60:
Cannot find module './locatedError.js' or its corresponding type declarations.
🤖 Prompt for AI Agents