Package graphql.parser
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 int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
Parses a string input into a graphql ASTDocument
parseDocument
(ParserEnvironment environment) Parses document text into a graphql ASTDocument
parseDocument
(Reader reader) Parses reader input into a graphql ASTDocument
parseDocument
(String input) Parses a string input into a graphql ASTDocument
static FieldDefinition
parseFieldDefinition
(String input) Parses a string input into a graphql ASTFieldDefinition
static 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
-
parseFieldDefinition
Parses a string input into a graphql ASTFieldDefinition
- Parameters:
input
- the input to parse- Returns:
- an AST
FieldDefinition
- 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
-
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
-