use of graphql.parser.ParserOptions in project graphql-java by graphql-java.
the class ParseAndValidate method parse.
/**
* This can be called to parse (but not validate) a graphql query.
*
* @param executionInput the input containing the query
*
* @return a result object that indicates how this operation went
*/
public static ParseAndValidateResult parse(ExecutionInput executionInput) {
try {
//
// we allow the caller to specify new parser options by context
ParserOptions parserOptions = executionInput.getGraphQLContext().get(ParserOptions.class);
Parser parser = new Parser();
Document document = parser.parseDocument(executionInput.getQuery(), parserOptions);
return ParseAndValidateResult.newResult().document(document).variables(executionInput.getVariables()).build();
} catch (InvalidSyntaxException e) {
return ParseAndValidateResult.newResult().syntaxException(e).variables(executionInput.getVariables()).build();
}
}
use of graphql.parser.ParserOptions in project graphql-java by graphql-java.
the class SchemaParser method parseImpl.
private TypeDefinitionRegistry parseImpl(Reader schemaInput, ParserOptions parseOptions) {
try {
if (parseOptions == null) {
// for SDL we don't stop how many parser tokens there are - it's not the attack vector
// to be prevented compared to queries
parseOptions = ParserOptions.getDefaultParserOptions().transform(opts -> opts.maxTokens(Integer.MAX_VALUE));
}
Parser parser = new Parser();
Document document = parser.parseDocument(schemaInput, parseOptions);
return buildRegistry(document);
} catch (InvalidSyntaxException e) {
throw handleParseException(e.toInvalidSyntaxError());
}
}
use of graphql.parser.ParserOptions in project graphql-maven-plugin-project by graphql-java-generator.
the class DocumentParser method parseDocuments.
/**
* The main method of the class: it graphqlUtils.executes the generation of the given documents
*
* @param documents
* The GraphQL definition schema, from which the code is to be generated
* @return
* @throws IOException
* When an error occurs, during the parsing of the GraphQL schemas
*/
public int parseDocuments() throws IOException {
logger.debug("Starting documents parsing");
// Configuration of the GraphQL schema parser, from the project configuration
ParserOptions newDefault = ParserOptions.newParserOptions().maxTokens(configuration.getMaxTokens()).build();
ParserOptions.setDefaultParserOptions(newDefault);
documents.getDocuments().stream().forEach(this::parseOneDocument);
logger.debug("Documents have been parsed. Executing internal finalizations");
// Let's finalize some "details":
// Init the list of the object implementing each interface. This is done last, when all objects has been read by
// the plugin.
logger.debug("Init list of interface implementations");
initListOfInterfaceImplementations();
// The types Map allows to retrieve easily a Type from its name
logger.debug("Fill type map");
fillTypesMap();
// Manage ObjectTypeExtensionDefinition: add the extension to the object they belong to
manageObjectTypeExtensionDefinition();
// Add the Relay connection capabilities, if configured for it
if (configuration.isAddRelayConnections()) {
addRelayConnections.addRelayConnections();
}
// We're done
int nbClasses = objectTypes.size() + enumTypes.size() + interfaceTypes.size();
logger.debug(documents.getDocuments().size() + " document(s) parsed (" + nbClasses + ")");
return nbClasses;
}
Aggregations