graphql.validation.ValidationErrorType Java Examples
The following examples show how to use
graphql.validation.ValidationErrorType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransformException.java From smallrye-graphql with Apache License 2.0 | 6 votes |
@Override public DataFetcherResult.Builder<Object> appendDataFetcherResult(DataFetcherResult.Builder<Object> builder, DataFetchingEnvironment dfe) { DataFetcherExceptionHandlerParameters handlerParameters = DataFetcherExceptionHandlerParameters .newExceptionParameters() .dataFetchingEnvironment(dfe) .exception(super.getCause()) .build(); SourceLocation sourceLocation = getSourceLocation(dfe, handlerParameters); List<String> paths = toPathList(handlerParameters.getPath()); ValidationError error = new ValidationError(ValidationErrorType.WrongType, sourceLocation, "argument '" + field.getName() + "' with value 'StringValue{value='" + parameterValue + "'}' is not a valid '" + getScalarTypeName() + "'", paths); return builder.error(error); }
Example #2
Source File: ExecutionErrorsServiceTest.java From smallrye-graphql with Apache License 2.0 | 6 votes |
@Test void testToJsonErrors_WhenExceptionWhileValidationErrorCaught_ShouldReturnJsonBodyWithCustomExtensions() { // Given Map<String, Object> extensions = new HashMap<>(); extensions.put("code", "OPERATION_FAILED"); ValidationError validationError = ValidationError.newValidationError() .validationErrorType(ValidationErrorType.UnknownDirective) .description("TestDescription") .queryPath(singletonList("Test-Path")) .extensions(extensions) .build(); // When JsonArray jsonArray = executionErrorsService.toJsonErrors(singletonList(validationError)); // Then JsonObject extensionJsonObject = jsonArray.getJsonObject(0).getJsonObject("extensions"); assertThat(extensionJsonObject.getString("description")).isEqualTo("TestDescription"); assertThat(extensionJsonObject.getString("validationErrorType")).isEqualTo("UnknownDirective"); assertThat(extensionJsonObject.getJsonArray("queryPath").getString(0)).isEqualTo("Test-Path"); assertThat(extensionJsonObject.getString("classification")).isEqualTo("ValidationError"); assertThat(extensionJsonObject.getString("code")).isEqualTo("OPERATION_FAILED"); }
Example #3
Source File: QueryValidator.java From hypergraphql with Apache License 2.0 | 3 votes |
public ValidatedQuery validateQuery(String query) { ValidatedQuery result = new ValidatedQuery(); result.errors = validationErrors; Document document; try { document = parser.parseDocument(query); result.parsedQuery = document; } catch (Exception e) { ValidationError err = new ValidationError(ValidationErrorType.InvalidSyntax, new SourceLocation(0, 0), "Invalid query syntax."); validationErrors.add(err); result.valid = false; return result; } validationErrors.addAll(validator.validateDocument(schema, document)); if (validationErrors.size() > 0) { result.valid = false; return result; } result.valid = true; return result; }
Example #4
Source File: QueryValidator.java From hypergraphql with Apache License 2.0 | 3 votes |
public ValidatedQuery validateQuery(String query) { ValidatedQuery result = new ValidatedQuery(); result.errors = validationErrors; Document document; try { document = parser.parseDocument(query); result.parsedQuery = document; } catch (Exception e) { ValidationError err = new ValidationError(ValidationErrorType.InvalidSyntax, new SourceLocation(0, 0), "Invalid query syntax."); validationErrors.add(err); result.valid = false; return result; } validationErrors.addAll(validator.validateDocument(schema, document)); if (validationErrors.size() > 0) { result.valid = false; return result; } result.valid = true; return result; }