graphql.parser.InvalidSyntaxException Java Examples
The following examples show how to use
graphql.parser.InvalidSyntaxException.
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: GqlModel.java From manifold with Apache License 2.0 | 6 votes |
private GraphQLError toGraphQLError( InvalidSyntaxException ise ) { return new GraphQLError() { @Override public String getMessage() { return ise.getMessage(); } @Override public List<SourceLocation> getLocations() { return Collections.singletonList( ise.getLocation() ); } @Override public ErrorClassification getErrorType() { return ErrorType.InvalidSyntax; } }; }
Example #2
Source File: FederatedTracingInstrumentation.java From federation-jvm with MIT License | 5 votes |
@NotNull private List<GraphQLError> convertErrors(Throwable throwable, Object result) { ArrayList<GraphQLError> graphQLErrors = new ArrayList<>(); if (throwable != null) { if (throwable instanceof GraphQLError) { graphQLErrors.add((GraphQLError) throwable); } else { String message = throwable.getMessage(); if (message == null) { message = "(null)"; } GraphqlErrorBuilder errorBuilder = GraphqlErrorBuilder.newError() .message(message); if (throwable instanceof InvalidSyntaxException) { errorBuilder.location(((InvalidSyntaxException) throwable).getLocation()); } graphQLErrors.add(errorBuilder.build()); } } if (result instanceof DataFetcherResult<?>) { DataFetcherResult<?> theResult = (DataFetcherResult) result; if (theResult.hasErrors()) { graphQLErrors.addAll(theResult.getErrors()); } } return graphQLErrors; }
Example #3
Source File: GraphQLAPIHandler.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public boolean handleRequest(MessageContext messageContext) { try { String payload; Parser parser = new Parser(); org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext). getAxis2MessageContext(); String requestPath = messageContext.getProperty(REST_SUB_REQUEST_PATH).toString(); if (requestPath != null && !requestPath.isEmpty()) { String[] queryParams = ((Axis2MessageContext) messageContext).getProperties(). get(REST_SUB_REQUEST_PATH).toString().split(QUERY_PATH_STRING); if (queryParams.length > 1) { payload = URLDecoder.decode(queryParams[1], UNICODE_TRANSFORMATION_FORMAT); } else { RelayUtils.buildMessage(axis2MC); OMElement body = axis2MC.getEnvelope().getBody().getFirstElement(); if (body != null && body.getFirstElement() != null) { payload = body.getFirstElement().getText(); } else { if (log.isDebugEnabled()) { log.debug("Invalid query parameter " + queryParams[0]); } handleFailure(messageContext, "Invalid query parameter"); return false; } } messageContext.setProperty(APIConstants.GRAPHQL_PAYLOAD, payload); } else { handleFailure(messageContext, "Request path cannot be empty"); return false; } // Validate payload with graphQLSchema Document document = parser.parseDocument(payload); if (validatePayloadWithSchema(messageContext, document)) { supportForBasicAndAuthentication(messageContext); // Extract the operation type and operations from the payload for (Definition definition : document.getDefinitions()) { if (definition instanceof OperationDefinition) { OperationDefinition operation = (OperationDefinition) definition; if (operation.getOperation() != null) { String httpVerb = ((Axis2MessageContext) messageContext).getAxis2MessageContext(). getProperty(HTTP_METHOD).toString(); messageContext.setProperty(HTTP_VERB, httpVerb); ((Axis2MessageContext) messageContext).getAxis2MessageContext().setProperty(HTTP_METHOD, operation.getOperation().toString()); String operationList = getOperationList(messageContext, operation); messageContext.setProperty(APIConstants.API_ELECTED_RESOURCE, operationList); if (log.isDebugEnabled()) { log.debug("Operation list has been successfully added to elected property"); } return true; } } else { handleFailure(messageContext, "Operation definition cannot be empty"); return false; } } } else { return false; } } catch (IOException | XMLStreamException | InvalidSyntaxException e) { log.error(e.getMessage()); handleFailure(messageContext, e.getMessage()); } return false; }