Class Parser
java.lang.Object
graphql.parser.Parser
- Direct Known Subclasses:
NodeToRuleCapturingParser
This can parse graphql syntax, both Query syntax and Schema Definition Language (SDL) syntax, into an
Abstract Syntax Tree (AST) represented by a
Document
You should not generally need to call this class as the GraphQL code sets this up for you
but if you are doing specific graphql utilities this class is essential.
Graphql syntax has a series of characters, such as spaces, new lines and commas that are not considered relevant to the syntax. However they can be captured and associated with the AST elements they belong to.
This costs more memory but for certain use cases (like editors) this maybe be useful. We have chosen to no capture
ignored characters by default but you can turn this on, either per parse or statically for the whole JVM
via ParserOptions.setDefaultParserOptions(ParserOptions) ()}}
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected GraphqlAntlrToLanguagegetAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader, ParserEnvironment environment) Allows you to override the ANTLR to AST code.static Documentparse(ParserEnvironment environment) Parses a string input into a graphql ASTDocumentstatic DocumentParses a string input into a graphql ASTDocumentparseDocument(ParserEnvironment environment) Parses document text into a graphql ASTDocumentparseDocument(Reader reader) Parses reader input into a graphql ASTDocumentparseDocument(Reader reader, ParserOptions parserOptions) Deprecated.parseDocument(String input) Parses a string input into a graphql ASTDocumentparseDocument(String input, ParserOptions parserOptions) Deprecated.use {#parse(ParserEnvironment)} insteadparseDocument(String input, String sourceName) Deprecated.use {#parse(ParserEnvironment)} insteadstatic Type<?> Parses a string input into a graphql AST Typestatic Value<?> parseValue(String input) Parses a string input into a graphql ASTValue
-
Field Details
-
CHANNEL_COMMENTS
public static final int CHANNEL_COMMENTS- See Also:
-
CHANNEL_WHITESPACE
public static final int CHANNEL_WHITESPACE- See Also:
-
-
Constructor Details
-
Parser
public Parser()
-
-
Method Details
-
parse
Parses a string input into a graphql ASTDocument- Parameters:
environment- the parser environment to use- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the document is not valid graphql syntax
-
parse
Parses a string input into a graphql ASTDocument- Parameters:
input- the input to parse- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseValue
Parses a string input into a graphql ASTValue- Parameters:
input- the input to parse- Returns:
- an AST
Value - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseType
Parses a string input into a graphql AST Type- Parameters:
input- the input to parse- Returns:
- an AST
Type - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
Parses document text into a graphql ASTDocument- Parameters:
environment- the parser environment to sue- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
Parses a string input into a graphql ASTDocument- Parameters:
input- the input to parse- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
Parses reader input into a graphql ASTDocument- Parameters:
reader- the reader input to parse- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
@Deprecated public Document parseDocument(String input, String sourceName) throws InvalidSyntaxException Deprecated.use {#parse(ParserEnvironment)} insteadParses a string input into a graphql ASTDocument- Parameters:
input- the input to parsesourceName- - the name to attribute to the input text inSourceLocation.getSourceName()- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
@Deprecated public Document parseDocument(String input, ParserOptions parserOptions) throws InvalidSyntaxException Deprecated.use {#parse(ParserEnvironment)} insteadParses a string input into a graphql ASTDocument- Parameters:
input- the input to parseparserOptions- the parser options- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
parseDocument
@Deprecated public Document parseDocument(Reader reader, ParserOptions parserOptions) throws InvalidSyntaxException Deprecated.use {#parse(ParserEnvironment)} insteadParses reader input into a graphql ASTDocument- Parameters:
reader- the reader input to parseparserOptions- the parser options- Returns:
- an AST
Document - Throws:
InvalidSyntaxException- if the input is not valid graphql syntax
-
getAntlrToLanguage
protected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader, ParserEnvironment environment) Allows you to override the ANTLR to AST code.- Parameters:
tokens- the token streammultiSourceReader- the source of the query documentenvironment- the parser environment- Returns:
- a new GraphqlAntlrToLanguage instance
-
parse(ParserEnvironment)} instead