SyntaxTree
SyntaxTree
new SyntaxTree()
A parser and processor of GraphQL IDL Abstract Syntax Trees. Used to combine
a set of GQLBase
class instances.
- Source:
- SyntaxTree.js, line 61
Members
(static, constant) ⬇︎⠀MUTATION :string
A runtime constant denoting a mutation type.
Type:
- string
- Source:
- SyntaxTree.js, line 667
(static, constant) ⬇︎⠀QUERY :string
A runtime constant denoting a query type.
Type:
- string
- Source:
- SyntaxTree.js, line 458
(static, constant) ⬇︎⠀QUERY :string
Ensures that the object type reported by Object.prototype.toString()
for SyntaxTree objects returns as [object SyntaxTree]. Used byutils#typeOf
Type:
- string
- Source:
- SyntaxTree.js, line 684
Methods
(static) ⌾⠀EmptyDocument(schemaOrASTOrST) → {SyntaxTree}
The starting point for a SyntaxTree that will be built up programmatically.
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string | Object | SyntaxTree | any valid type taken by |
Returns:
(
SyntaxTree
)
an instance of SyntaxTree with no definitions and a
kind set to 'Document'
- Source:
- SyntaxTree.js, line 627
(static) ⌾⠀EmptyMutation() → {SyntaxTree}
Mutation types in GraphQL are an ObjectTypeDefinition of importance for
placement on the root object. There is utility in creating an empty
one that can be injected with the fields of other GraphQL object mutation
entries.
Returns:
(
SyntaxTree
)
an instance of SyntaxTree with a base AST generated
by parsing the graph query, "type Mutation {}"
- Source:
- SyntaxTree.js, line 607
(static) ⌾⠀EmptyQuery() → {SyntaxTree}
Query types in GraphQL are an ObjectTypeDefinition of importance for
placement on the root object. There is utility in creating an empty
one that can be injected with the fields of other GraphQL object query
entries.
Returns:
(
SyntaxTree
)
an instance of SyntaxTree with a base AST generated
by parsing the graph query, "type Query {}"
- Source:
- SyntaxTree.js, line 587
(static) ⌾⠀from(mixed) → {SyntaxTree}
Given one of, a valid GraphQL IDL schema string, a valid GraphQL AST or
an instance of SyntaxTree, the static from() method will create a new
instance of the SyntaxTree with the values you provide.
Parameters:
Name | Type | Description |
---|---|---|
mixed |
String | Object | SyntaxTree | an instance of one of the valid |
Returns:
(
SyntaxTree
)
a newly created and populated instance of SyntaxTree
or null if an invalid type was supplied for mixed.
- Source:
- SyntaxTree.js, line 494
(static) ⌾⠀fromAST(ast) → {SyntaxTree}
Generates a new instance of SyntaxTree from the supplied, valid, GraphQL
schema. This method does not perform try/catch validation and if an
invalid GraphQL schema is supplied an error will be thrown.
Parameters:
Name | Type | Description |
---|---|---|
ast |
object | a valid GraphQL AST object. |
Returns:
(
SyntaxTree
)
a new instance of SyntaxTree initialized with a
supplied abstract syntax tree generated by require('graphql').parse() or
other compatible method.
- Source:
- SyntaxTree.js, line 563
(static) ⌾⠀fromSchema(schema) → {SyntaxTree}
Generates a new instance of SyntaxTree from the supplied, valid, GraphQL
schema. This method does not perform try/catch validation and if an
invalid GraphQL schema is supplied an error will be thrown.
Parameters:
Name | Type | Description |
---|---|---|
schema |
string | a valid GraphQL IDL schema string. |
Returns:
(
SyntaxTree
)
a new instance of SyntaxTree initialized with a
parsed response from require('graphql').parse().
- Source:
- SyntaxTree.js, line 540
⌾⠀appendDefinitions(schemaOrASTOrST) → {SyntaxTree}
Appends all definitions from another AST to this one. The method will
actually create a copy using SyntaxTree.from() so the input types can
be any one of a valid GraphQL IDL schema string, a GraphQL IDL AST or
another SyntaxTree object instance.
Definitions of the same name but different kinds will be replaced by the
new copy. Those of the same kind and name will be merged (TODO handle more
than ObjectTypeDefinition kinds when merging; currently other types are
overwritten).
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string | Object | SyntaxTree | an instance of one of |
Returns:
(
SyntaxTree
)
this for inlining
- Source:
- SyntaxTree.js, line 194
⌾⠀consumeDefinition(astOrSyntaxTree, definitionType) → {SyntaxTree}
This method finds the Query type definitions in the supplied AST or
SyntaxTree objects, takes its defined fields and adds it to the current
instances. If this instance does not have a Query type defined but the
supplied object does, then the supplied one is moved over. If neither
has a query handler, then nothing happens.
NOTE this removes the Query type definition from the supplied AST or
SyntaxTree object.
Parameters:
Name | Type | Description |
---|---|---|
astOrSyntaxTree |
Object | SyntaxTree | a valid GraphQL IDL AST or |
definitionType |
string | RegExp | a valid search input as would be |
Returns:
(
SyntaxTree
)
returns this for inlining
- Source:
- SyntaxTree.js, line 288
⌾⠀find(definitionName) → {Object|null}
Iterate through the definitions of the AST if there are any. For each
definition the name property's value field is compared to the supplied
definitionName. The definitionName can be a string or a regular
expression if finer granularity is desired.
Parameters:
Name | Type | Description |
---|---|---|
definitionName |
string | RegExp | a string or regular expression used |
Returns:
(
Object
|
null
)
a reference to the internal definition field or
null if one with a matching name could not be found.
- Source:
- SyntaxTree.js, line 407
⌾⠀setAST(schemaOrAST) → {SyntaxTree}
Sets the underlying AST object with either schema which will be parsed
into a valid AST or an existing AST. Previous ast values will be erased.
Parameters:
Name | Type | Description |
---|---|---|
schemaOrAST |
string | Object | a valid GraphQL IDL schema or a |
Returns:
(
SyntaxTree
)
this for inlining.
- Source:
- SyntaxTree.js, line 110
⌾⠀toString() → {string}
SyntaxTree instances that are toString()'ed will have the graphql method
print() called on them to convert their internal structures back to a
GraphQL IDL schema syntax. If the object is in an invalid state, it WILL
throw an error.
Returns:
(
string
)
the AST for the tree parsed back into a string
- Source:
- SyntaxTree.js, line 439
⌾⠀updateAST(ast) → {SyntaxTree}
As passthru update method that works on the internal AST object. If
an error occurs, the update is skipped. An error can occur if adding the
changes would make the AST invalid. In such a case, the error is logged
to the error console.
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object | an existing GraphQL IDL AST object that will be |
Returns:
(
SyntaxTree
)
this for inlining.
- Source:
- SyntaxTree.js, line 159
⎆⠀constructor(schemaOrASTOrST)
Constructs a new SyntaxTree
object. If a string schema is supplied or
an already parsed AST object, either of which is valid GraphQL IDL, then
its parsed AST will be the internals of this object.
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string | Object | SyntaxTree | if supplied the tree |
- Source:
- SyntaxTree.js, line 69
⬆︎⠀ast(value)
Setter that assigns the abstract syntax tree, typically created bygraphql.parse
when given a valid string of IDL.
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | a valid AST object. Other operations will act |
- Source:
- SyntaxTree.js, line 475
⬇︎⠀ast() → {Object}
Getter that retrieves the abstract syntax tree created by graphql.parse
when it is presented with a valid string of IDL.
Returns:
(
Object
)
a GraphQL AST object
- Source:
- SyntaxTree.js, line 94