File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
17
17
assertScalarType ,
18
18
assertUnionType ,
19
19
} from '../../type/definition' ;
20
- import { assertDirective } from '../../type/directives' ;
20
+ import { assertDirective , specifiedDirectives } from '../../type/directives' ;
21
21
import {
22
22
GraphQLBoolean ,
23
23
GraphQLFloat ,
@@ -85,6 +85,34 @@ describe('extendSchema', () => {
85
85
} ) ;
86
86
} ) ;
87
87
88
+ it ( 'Do not modify built-in types and directives' , ( ) => {
89
+ const schema = buildSchema ( `
90
+ type Query {
91
+ str: String
92
+ int: Int
93
+ float: Float
94
+ id: ID
95
+ bool: Boolean
96
+ }
97
+ ` ) ;
98
+
99
+ const extensionSDL = dedent `
100
+ extend type Query {
101
+ foo: String
102
+ }
103
+ ` ;
104
+ const extendedSchema = extendSchema ( schema , parse ( extensionSDL ) ) ;
105
+
106
+ // Built-ins are used
107
+ expect ( extendedSchema . getType ( 'Int' ) ) . to . equal ( GraphQLInt ) ;
108
+ expect ( extendedSchema . getType ( 'Float' ) ) . to . equal ( GraphQLFloat ) ;
109
+ expect ( extendedSchema . getType ( 'String' ) ) . to . equal ( GraphQLString ) ;
110
+ expect ( extendedSchema . getType ( 'Boolean' ) ) . to . equal ( GraphQLBoolean ) ;
111
+ expect ( extendedSchema . getType ( 'ID' ) ) . to . equal ( GraphQLID ) ;
112
+
113
+ expect ( extendedSchema . getDirectives ( ) ) . to . have . members ( specifiedDirectives ) ;
114
+ } ) ;
115
+
88
116
it ( 'extends objects by adding new fields' , ( ) => {
89
117
const schema = buildSchema ( `
90
118
type Query {
Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ import {
67
67
GraphQLDeprecatedDirective ,
68
68
GraphQLDirective ,
69
69
GraphQLSpecifiedByDirective ,
70
+ isSpecifiedDirective ,
70
71
} from '../type/directives' ;
71
72
import { introspectionTypes , isIntrospectionType } from '../type/introspection' ;
72
73
import { isSpecifiedScalarType , specifiedScalarTypes } from '../type/scalars' ;
@@ -236,6 +237,11 @@ export function extendSchemaImpl(
236
237
}
237
238
238
239
function replaceDirective ( directive : GraphQLDirective ) : GraphQLDirective {
240
+ if ( isSpecifiedDirective ( directive ) ) {
241
+ // Builtin directives are not extended.
242
+ return directive ;
243
+ }
244
+
239
245
const config = directive . toConfig ( ) ;
240
246
return new GraphQLDirective ( {
241
247
...config ,
You can’t perform that action at this time.
0 commit comments