Package graphql.parser
Class Parser
- java.lang.Object
-
- graphql.parser.Parser
-
- Direct Known Subclasses:
NodeToRuleCapturingParser
@PublicApi public class Parser extends java.lang.Object
This can parse graphql syntax, both Query syntax and Schema Definition Language (SDL) syntax, into an Abstract Syntax Tree (AST) represented by aDocument
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:
IgnoredChar
-
-
Field Summary
Fields Modifier and Type Field Description static int
CHANNEL_COMMENTS
static int
CHANNEL_WHITESPACE
-
Constructor Summary
Constructors Constructor Description Parser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 ASTDocument
static Document
parse(java.lang.String input)
Parses a string input into a graphql ASTDocument
Document
parseDocument(ParserEnvironment environment)
Parses document text into a graphql ASTDocument
Document
parseDocument(java.io.Reader reader)
Parses reader input into a graphql ASTDocument
Document
parseDocument(java.lang.String input)
Parses a string input into a graphql ASTDocument
static Type<?>
parseType(java.lang.String input)
Parses a string input into a graphql AST Typestatic Value<?>
parseValue(java.lang.String input)
Parses a string input into a graphql ASTValue
-
-
-
Field Detail
-
CHANNEL_COMMENTS
public static final int CHANNEL_COMMENTS
- See Also:
- Constant Field Values
-
CHANNEL_WHITESPACE
public static final int CHANNEL_WHITESPACE
- See Also:
- Constant Field Values
-
-
Method Detail
-
parse
public static Document parse(ParserEnvironment environment) throws InvalidSyntaxException
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
public static Document parse(java.lang.String input) throws InvalidSyntaxException
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
public static Value<?> parseValue(java.lang.String input) throws InvalidSyntaxException
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
public static Type<?> parseType(java.lang.String input) throws InvalidSyntaxException
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
public Document parseDocument(ParserEnvironment environment) throws InvalidSyntaxException
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
public Document parseDocument(java.lang.String input) throws InvalidSyntaxException
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
public Document parseDocument(java.io.Reader reader) throws InvalidSyntaxException
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
-
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
-
-