@@ -99,7 +99,12 @@ export const topologicalSortAST = (schema: GraphQLSchema, ast: DocumentNode): Do
99
99
100
100
// Create a map of definitions for quick access, using the definition's name as the key.
101
101
const definitionsMap : Map < string , DefinitionNode > = new Map ( ) ;
102
- ast . definitions . forEach ( definition => {
102
+
103
+ // SCHEMA_DEFINITION does not have name.
104
+ // https://spec.graphql.org/October2021/#sec-Schema
105
+ const astDefinitions = ast . definitions . filter ( def => def . kind !== 'SchemaDefinition' ) ;
106
+
107
+ astDefinitions . forEach ( definition => {
103
108
if ( hasNameField ( definition ) && definition . name ) {
104
109
definitionsMap . set ( definition . name . value , definition ) ;
105
110
}
@@ -122,17 +127,17 @@ export const topologicalSortAST = (schema: GraphQLSchema, ast: DocumentNode): Do
122
127
// Add them to notSortedDefinitions.
123
128
definitionsMap . forEach ( definition => notSortedDefinitions . push ( definition ) ) ;
124
129
125
- const definitions = [ ...sortedDefinitions , ...notSortedDefinitions ] ;
130
+ const newDefinitions = [ ...sortedDefinitions , ...notSortedDefinitions ] ;
126
131
127
- if ( definitions . length !== ast . definitions . length ) {
132
+ if ( newDefinitions . length !== astDefinitions . length ) {
128
133
throw new Error (
129
- `unexpected definition length after sorted: want ${ ast . definitions . length } but got ${ definitions . length } `
134
+ `unexpected definition length after sorted: want ${ astDefinitions . length } but got ${ newDefinitions . length } `
130
135
) ;
131
136
}
132
137
133
138
return {
134
139
...ast ,
135
- definitions : definitions as ReadonlyArray < DefinitionNode > ,
140
+ definitions : newDefinitions as ReadonlyArray < DefinitionNode > ,
136
141
} ;
137
142
} ;
138
143
0 commit comments