( schema: GraphQLSchema, documentAST: DocumentNode, rules: ReadonlyArray<ValidationRule>, options: ValidationOptions | undefined, )
| 130 | } |
| 131 | |
| 132 | function validateImpl( |
| 133 | schema: GraphQLSchema, |
| 134 | documentAST: DocumentNode, |
| 135 | rules: ReadonlyArray<ValidationRule>, |
| 136 | options: ValidationOptions | undefined, |
| 137 | ): ReadonlyArray<GraphQLError> { |
| 138 | const maxErrors = options?.maxErrors ?? 100; |
| 139 | const hideSuggestions = options?.hideSuggestions ?? false; |
| 140 | |
| 141 | // If the schema used for validation is invalid, throw an error. |
| 142 | assertValidSchema(schema); |
| 143 | |
| 144 | const errors: Array<GraphQLError> = []; |
| 145 | const typeInfo = new TypeInfo(schema); |
| 146 | const context = new ValidationContext( |
| 147 | schema, |
| 148 | documentAST, |
| 149 | typeInfo, |
| 150 | (error) => { |
| 151 | if (errors.length >= maxErrors) { |
| 152 | throw tooManyValidationErrorsError; |
| 153 | } |
| 154 | errors.push(error); |
| 155 | }, |
| 156 | hideSuggestions, |
| 157 | ); |
| 158 | |
| 159 | // This uses a specialized visitor which runs multiple visitors in parallel, |
| 160 | // while maintaining the visitor skip and break API. |
| 161 | const visitor = visitInParallel(rules.map((rule) => rule(context))); |
| 162 | |
| 163 | // Visit the whole document with each instance of all provided rules. |
| 164 | try { |
| 165 | visit( |
| 166 | documentAST, |
| 167 | visitWithTypeInfo(typeInfo, visitor), |
| 168 | QueryDocumentKeysToValidate, |
| 169 | ); |
| 170 | } catch (e: unknown) { |
| 171 | if (e === tooManyValidationErrorsError) { |
| 172 | errors.push(tooManyValidationErrorsError); |
| 173 | } else { |
| 174 | throw e; |
| 175 | } |
| 176 | } |
| 177 | return errors; |
| 178 | } |
| 179 | |
| 180 | /** @internal */ |
| 181 | export function validateSDL( |
no test coverage detected