Skip to content

Commit b04b242

Browse files
committed
Use createGraphQLError
1 parent 52ba07b commit b04b242

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.changeset/stupid-webs-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/import': patch
3+
---
4+
5+
enhance GraphQL schema import error debugging with source locations

packages/import/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
UnionTypeExtensionNode,
4141
} from 'graphql';
4242
import resolveFrom from 'resolve-from';
43-
import { parseGraphQLSDL } from '@graphql-tools/utils';
43+
import { createGraphQLError, parseGraphQLSDL } from '@graphql-tools/utils';
4444
import { extractLinkImplementations } from '@theguild/federation-composition';
4545

4646
const builtinTypes = ['String', 'Float', 'Int', 'Boolean', 'ID', 'Upload'];
@@ -287,9 +287,9 @@ function visitFile(
287287
!allImportedDefinitionsMap.has(dependencyName) &&
288288
!definitionsByName.has(dependencyName)
289289
) {
290-
throw new GraphQLError(
290+
throw createGraphQLError(
291291
`Couldn't find type ${dependencyName} in any of the schemas.`,
292-
Array.from(dependencyNodes),
292+
{ nodes: Array.from(dependencyNodes) },
293293
);
294294
}
295295
const dependencyDefinitionsFromImports =

packages/utils/tests/mergeIncrementalResult.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,43 +102,43 @@ describe('mergeIncrementalResult', () => {
102102
it('should add errors', () => {
103103
const executionResult = { data: { user: { name: 'John' } } };
104104
const incrementalResult = {
105-
errors: [new GraphQLError('error 1'), new GraphQLError('error 2')],
105+
errors: [createGraphQLError('error 1'), createGraphQLError('error 2')],
106106
};
107107

108108
mergeIncrementalResult({ incrementalResult, executionResult });
109109

110110
expect(executionResult).toEqual({
111111
data: { user: { name: 'John' } },
112-
errors: [new GraphQLError('error 1'), new GraphQLError('error 2')],
112+
errors: [createGraphQLError('error 1'), createGraphQLError('error 2')],
113113
});
114114
});
115115

116116
it('should keep errors', () => {
117-
const executionResult = { errors: [new GraphQLError('error 1')] };
117+
const executionResult = { errors: [createGraphQLError('error 1')] };
118118
const incrementalResult = { data: { user: { name: 'John' } }, path: [] };
119119

120120
mergeIncrementalResult({ incrementalResult, executionResult });
121121

122122
expect(executionResult).toEqual({
123123
data: { user: { name: 'John' } },
124-
errors: [new GraphQLError('error 1')],
124+
errors: [createGraphQLError('error 1')],
125125
});
126126
});
127127

128128
it('should merge errors', () => {
129-
const executionResult = { errors: [new GraphQLError('error 1')] };
129+
const executionResult = { errors: [createGraphQLError('error 1')] };
130130

131131
const incrementalResult = {
132-
errors: [new GraphQLError('error 2'), new GraphQLError('error 3')],
132+
errors: [createGraphQLError('error 2'), createGraphQLError('error 3')],
133133
};
134134

135135
mergeIncrementalResult({ incrementalResult, executionResult });
136136

137137
expect(executionResult).toEqual({
138138
errors: [
139-
new GraphQLError('error 1'),
140-
new GraphQLError('error 2'),
141-
new GraphQLError('error 3'),
139+
createGraphQLError('error 1'),
140+
createGraphQLError('error 2'),
141+
createGraphQLError('error 3'),
142142
],
143143
});
144144
});

0 commit comments

Comments
 (0)