File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717 assertScalarType ,
1818 assertUnionType ,
1919} from '../../type/definition' ;
20- import { assertDirective } from '../../type/directives' ;
20+ import { assertDirective , specifiedDirectives } from '../../type/directives' ;
2121import {
2222 GraphQLBoolean ,
2323 GraphQLFloat ,
@@ -85,6 +85,34 @@ describe('extendSchema', () => {
8585 } ) ;
8686 } ) ;
8787
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+
88116 it ( 'extends objects by adding new fields' , ( ) => {
89117 const schema = buildSchema ( `
90118 type Query {
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ import {
6868 GraphQLDirective ,
6969 GraphQLOneOfDirective ,
7070 GraphQLSpecifiedByDirective ,
71+ isSpecifiedDirective ,
7172} from '../type/directives' ;
7273import { introspectionTypes , isIntrospectionType } from '../type/introspection' ;
7374import { isSpecifiedScalarType , specifiedScalarTypes } from '../type/scalars' ;
@@ -237,6 +238,11 @@ export function extendSchemaImpl(
237238 }
238239
239240 function replaceDirective ( directive : GraphQLDirective ) : GraphQLDirective {
241+ if ( isSpecifiedDirective ( directive ) ) {
242+ // Builtin directives are not extended.
243+ return directive ;
244+ }
245+
240246 const config = directive . toConfig ( ) ;
241247 return new GraphQLDirective ( {
242248 ...config ,
You can’t perform that action at this time.
0 commit comments