File tree 2 files changed +23
-1
lines changed 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -802,4 +802,22 @@ fragment Foo on Type { field }
802
802
. to . throw ( 'Specified query type "Foo" not found in document.' ) ;
803
803
} ) ;
804
804
805
+ it ( 'Forbids duplicate type definitions' , ( ) => {
806
+ const body = `
807
+ schema {
808
+ query: Repeated
809
+ }
810
+
811
+ type Repeated {
812
+ id: Int
813
+ }
814
+
815
+ type Repeated {
816
+ id: String
817
+ }
818
+ ` ;
819
+ const doc = parse ( body ) ;
820
+ expect ( ( ) => buildASTSchema ( doc ) )
821
+ . to . throw ( 'Type "Repeated" was defined more than once.' ) ;
822
+ } ) ;
805
823
} ) ;
Original file line number Diff line number Diff line change @@ -160,8 +160,12 @@ export function buildASTSchema(ast: DocumentNode): GraphQLSchema {
160
160
case ENUM_TYPE_DEFINITION :
161
161
case UNION_TYPE_DEFINITION :
162
162
case INPUT_OBJECT_TYPE_DEFINITION :
163
+ const typeName = d . name . value ;
164
+ if ( nodeMap [ typeName ] ) {
165
+ throw new Error ( `Type "${ typeName } " was defined more than once.` ) ;
166
+ }
163
167
typeDefs . push ( d ) ;
164
- nodeMap [ d . name . value ] = d ;
168
+ nodeMap [ typeName ] = d ;
165
169
break ;
166
170
case DIRECTIVE_DEFINITION :
167
171
directiveDefs . push ( d ) ;
You can’t perform that action at this time.
0 commit comments