Skip to content

Commit 3b99a9b

Browse files
n1ru4lardatan
andauthored
fix(utils/mapSchema): do not map builtin scalars (#5294)
* add failing test * Fix --------- Co-authored-by: Arda TANRIKULU <[email protected]>
1 parent 1a6251d commit 3b99a9b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

.changeset/social-pots-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
Do not map builtin scalars

packages/utils/src/mapSchema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
GraphQLNonNull,
1515
GraphQLObjectType,
1616
GraphQLObjectTypeConfig,
17+
GraphQLScalarType,
1718
GraphQLSchema,
1819
GraphQLType,
1920
InputValueDefinitionNode,
@@ -28,6 +29,7 @@ import {
2829
isScalarType,
2930
isUnionType,
3031
Kind,
32+
specifiedScalarTypes,
3133
} from 'graphql';
3234
import { getObjectTypeFromTypeMap } from './getObjectTypeFromTypeMap.js';
3335
import {
@@ -109,7 +111,10 @@ function mapTypes(
109111
if (!typeName.startsWith('__')) {
110112
const originalType = originalTypeMap[typeName];
111113

112-
if (originalType == null || !testFn(originalType)) {
114+
if (
115+
originalType == null ||
116+
(!testFn(originalType) && !specifiedScalarTypes.includes(originalType as GraphQLScalarType))
117+
) {
113118
newTypeMap[typeName] = originalType;
114119
continue;
115120
}

packages/utils/tests/mapSchema.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ describe('mapSchema', () => {
9393
expect(newSchema.getQueryType()?.name).toBe('RootQuery');
9494
});
9595

96+
test('map scalar type', () => {
97+
const schema = buildSchema(/* GraphQL */ `
98+
type Query {
99+
_: Boolean
100+
}
101+
`);
102+
103+
mapSchema(schema, {
104+
[MapperKind.SCALAR_TYPE](type) {
105+
const config = type.toConfig();
106+
return new GraphQLScalarType({
107+
...config,
108+
});
109+
},
110+
});
111+
});
112+
96113
const typeDefs = /* GraphQL */ `
97114
directive @schemaDirective(role: String) on SCHEMA
98115
directive @schemaExtensionDirective(role: String) on SCHEMA

0 commit comments

Comments
 (0)