(context: SchemaValidationContext)
| 165 | } |
| 166 | |
| 167 | function validateRootTypes(context: SchemaValidationContext): void { |
| 168 | const schema = context.schema; |
| 169 | |
| 170 | if (schema.getQueryType() == null) { |
| 171 | context.reportError('Query root type must be provided.', schema.astNode); |
| 172 | } |
| 173 | |
| 174 | const rootTypesMap = new AccumulatorMap< |
| 175 | GraphQLObjectType, |
| 176 | OperationTypeNode |
| 177 | >(); |
| 178 | for (const operationType of Object.values(OperationTypeNode)) { |
| 179 | const rootType = schema.getRootType(operationType); |
| 180 | |
| 181 | if (rootType != null) { |
| 182 | if (!isObjectType(rootType)) { |
| 183 | const operationTypeStr = capitalize(operationType); |
| 184 | const rootTypeStr = inspect(rootType); |
| 185 | context.reportError( |
| 186 | operationType === OperationTypeNode.QUERY |
| 187 | ? `${operationTypeStr} root type must be Object type, it cannot be ${rootTypeStr}.` |
| 188 | : `${operationTypeStr} root type must be Object type if provided, it cannot be ${rootTypeStr}.`, |
| 189 | getOperationTypeNode(schema, operationType) ?? |
| 190 | (rootType as any).astNode, |
| 191 | ); |
| 192 | } else { |
| 193 | rootTypesMap.add(rootType, operationType); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | for (const [rootType, operationTypes] of rootTypesMap) { |
| 199 | if (operationTypes.length > 1) { |
| 200 | const operationList = andList(operationTypes); |
| 201 | context.reportError( |
| 202 | `All root types must be different, "${rootType}" type is used as ${operationList} root types.`, |
| 203 | operationTypes.map((operationType) => |
| 204 | getOperationTypeNode(schema, operationType), |
| 205 | ), |
| 206 | ); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | function getOperationTypeNode( |
| 212 | schema: GraphQLSchema, |
no test coverage detected