@PublicApi public class Parser extends java.lang.Object
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)
()}}
IgnoredChar
Modifier and Type | Field and Description |
---|---|
static int |
CHANNEL_COMMENTS |
static int |
CHANNEL_WHITESPACE |
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
protected GraphqlAntlrToLanguage |
getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens,
MultiSourceReader multiSourceReader,
ParserEnvironment environment)
Allows you to override the ANTLR to AST code.
|
static Document |
parse(ParserEnvironment environment)
Parses a string input into a graphql AST
Document |
static Document |
parse(java.lang.String input)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(ParserEnvironment environment)
Parses document text into a graphql AST
Document |
Document |
parseDocument(java.io.Reader reader)
Parses reader input into a graphql AST
Document |
Document |
parseDocument(java.io.Reader reader,
ParserOptions parserOptions)
Deprecated.
use {#
parse(ParserEnvironment) } instead |
Document |
parseDocument(java.lang.String input)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input,
ParserOptions parserOptions)
Deprecated.
use {#
parse(ParserEnvironment) } instead |
Document |
parseDocument(java.lang.String input,
java.lang.String sourceName)
Deprecated.
use {#
parse(ParserEnvironment) } instead |
static Type<?> |
parseType(java.lang.String input)
Parses a string input into a graphql AST Type
|
static Value<?> |
parseValue(java.lang.String input)
Parses a string input into a graphql AST
Value |
public static final int CHANNEL_COMMENTS
public static final int CHANNEL_WHITESPACE
public static Document parse(ParserEnvironment environment) throws InvalidSyntaxException
Document
environment
- the parser environment to useDocument
InvalidSyntaxException
- if the document is not valid graphql syntaxpublic static Document parse(java.lang.String input) throws InvalidSyntaxException
Document
input
- the input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic static Value<?> parseValue(java.lang.String input) throws InvalidSyntaxException
Value
input
- the input to parseValue
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic static Type<?> parseType(java.lang.String input) throws InvalidSyntaxException
input
- the input to parseType
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(ParserEnvironment environment) throws InvalidSyntaxException
Document
environment
- the parser environment to sueDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.lang.String input) throws InvalidSyntaxException
Document
input
- the input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.io.Reader reader) throws InvalidSyntaxException
Document
reader
- the reader input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntax@Deprecated public Document parseDocument(java.lang.String input, java.lang.String sourceName) throws InvalidSyntaxException
parse(ParserEnvironment)
} insteadDocument
input
- the input to parsesourceName
- - the name to attribute to the input text in SourceLocation.getSourceName()
Document
InvalidSyntaxException
- if the input is not valid graphql syntax@Deprecated public Document parseDocument(java.lang.String input, ParserOptions parserOptions) throws InvalidSyntaxException
parse(ParserEnvironment)
} insteadDocument
input
- the input to parseparserOptions
- the parser optionsDocument
InvalidSyntaxException
- if the input is not valid graphql syntax@Deprecated public Document parseDocument(java.io.Reader reader, ParserOptions parserOptions) throws InvalidSyntaxException
parse(ParserEnvironment)
} insteadDocument
reader
- the reader input to parseparserOptions
- the parser optionsDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxprotected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader, ParserEnvironment environment)
tokens
- the token streammultiSourceReader
- the source of the query documentenvironment
- the parser environment