@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
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
protected GraphqlAntlrToLanguage |
getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens,
MultiSourceReader multiSourceReader)
Deprecated.
- really should use
getAntlrToLanguage(CommonTokenStream, MultiSourceReader, ParserOptions) |
protected GraphqlAntlrToLanguage |
getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens,
MultiSourceReader multiSourceReader,
ParserOptions parserOptions)
Allows you to override the ANTLR to AST code.
|
static Document |
parse(java.lang.String input)
Parses a string input 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)
Parses reader input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input,
ParserOptions parserOptions)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input,
java.lang.String sourceName)
Parses a string input into a graphql AST
Document |
static Value<?> |
parseValue(java.lang.String input)
Parses a string input into a graphql AST
Value |
public 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 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.lang.String input, java.lang.String sourceName) throws InvalidSyntaxException
Document
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 syntaxpublic Document parseDocument(java.lang.String input, ParserOptions parserOptions) throws InvalidSyntaxException
Document
input
- the input to parseparserOptions
- the parser optionsDocument
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 syntaxpublic Document parseDocument(java.io.Reader reader, ParserOptions parserOptions) throws InvalidSyntaxException
Document
reader
- the reader input to parseparserOptions
- the parser optionsDocument
InvalidSyntaxException
- if the input is not valid graphql syntax@Deprecated protected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader)
getAntlrToLanguage(CommonTokenStream, MultiSourceReader, ParserOptions)
tokens
- the token streammultiSourceReader
- the source of the query documentprotected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader, ParserOptions parserOptions)
tokens
- the token streammultiSourceReader
- the source of the query documentparserOptions
- - the parser options