File tree Expand file tree Collapse file tree 2 files changed +36
-12
lines changed Expand file tree Collapse file tree 2 files changed +36
-12
lines changed Original file line number Diff line number Diff line change @@ -341,15 +341,27 @@ describe('Type System: Objects must have fields', () => {
341
341
) ;
342
342
} ) ;
343
343
344
- it ( 'rejects an Object type with reserved named fields' , ( ) => {
345
- expect (
346
- ( ) => schemaWithFieldType ( new GraphQLObjectType ( {
344
+ it ( 'warns when an Object type with reserved named fields' , ( ) => {
345
+ /* eslint-disable no-console */
346
+ const prevConsoleError = console . error ;
347
+ const calls = [ ] ;
348
+ console . error = function ( ) {
349
+ calls . push ( Array . prototype . slice . call ( arguments ) ) ;
350
+ } ;
351
+ try {
352
+ schemaWithFieldType ( new GraphQLObjectType ( {
347
353
name : 'SomeObject' ,
348
354
fields : { __notPartOfIntrospection : { type : GraphQLString } }
349
- } ) )
350
- ) . to . throw (
351
- 'Name "__notPartOfIntrospection" must not begin with "__", which is reserved by GraphQL introspection.'
352
- ) ;
355
+ } ) ) ;
356
+
357
+ expect ( calls [ 0 ] [ 0 ] ) . contains ( [
358
+ [ 'GraphQL: Name "__notPartOfIntrospection" must not begin with ' +
359
+ '"__", which is reserved by GraphQL introspection.' ]
360
+ ] ) ;
361
+ } finally {
362
+ console . error = prevConsoleError ;
363
+ }
364
+ /* eslint-enable no-console */
353
365
} ) ;
354
366
355
367
it ( 'rejects an Object type with incorrectly typed fields' , ( ) => {
Original file line number Diff line number Diff line change 10
10
11
11
const NAME_RX = / ^ [ _ a - z A - Z ] [ _ a - z A - Z 0 - 9 ] * $ / ;
12
12
13
+ // Ensures console warnings are only issued once.
14
+ let hasWarnedAboutDunder = false ;
15
+
13
16
/**
14
17
* Upholds the spec rules about naming.
15
18
*/
@@ -22,11 +25,20 @@ export function assertValidName(
22
25
`Must be named. Unexpected name: ${ name } .`
23
26
) ;
24
27
}
25
- if ( ! isIntrospection && name . slice ( 0 , 2 ) === '__' ) {
26
- throw new Error (
27
- `Name "${ name } " must not begin with "__", which is reserved by ` +
28
- 'GraphQL introspection.'
29
- ) ;
28
+ if ( ! isIntrospection && name . slice ( 0 , 2 ) === '__' && ! hasWarnedAboutDunder ) {
29
+ hasWarnedAboutDunder = true ;
30
+ /* eslint-disable no-console */
31
+ if ( console && console . error ) {
32
+ const stack = new Error ( ) . stack ;
33
+ const stackOnly = stack ?
34
+ '\n' + stack . split ( '\n' ) . slice ( 1 ) . join ( '\n' ) :
35
+ '' ;
36
+ console . error (
37
+ `GraphQL: Name "${ name } " must not begin with "__", which is ` +
38
+ 'reserved by GraphQL introspection.' + stackOnly
39
+ ) ;
40
+ }
41
+ /* eslint-enable no-console */
30
42
}
31
43
if ( ! NAME_RX . test ( name ) ) {
32
44
throw new Error (
You can’t perform that action at this time.
0 commit comments