new SyntaxTree()
A parser and processor of GraphQL IDL Abstract Syntax Trees. Used to combine
a set of GQLBase
class instances.
- Source:
Members
(static, constant) SUBSCRIPTION :string
A runtime constant denoting a subscription type.
- Source:
Type:
-
string
(static, constant) ⬇︎⠀MUTATION :string
A runtime constant denoting a mutation type.
- Source:
Type:
-
string
(static, constant) ⬇︎⠀QUERY :string
A runtime constant denoting a query type.
- Source:
Type:
-
string
Methods
(static) ⌾⠀EmptyDocument(schemaOrASTOrST) → {SyntaxTree}
The starting point for a SyntaxTree that will be built up programmatically.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string
|
Object
|
SyntaxTree
|
any valid type taken by |
(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.
- Source:
Returns:
- Type:
-
SyntaxTree
an instance of SyntaxTree with a base AST generated
by parsing the graph query, "type Mutation {}"
(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.
- Source:
Returns:
- Type:
-
SyntaxTree
an instance of SyntaxTree with a base AST generated
by parsing the graph query, "type Query {}"
(static) ⌾⠀findDefinition(ast, 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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object
|
an abstract syntax tree object created from a GQL SDL |
definitionName |
string
|
RegExp
|
a string or regular expression used |
Returns:
- Type:
-
Object
|null
a reference to the internal definition field or
null if one with a matching name could not be found.
(static) ⌾⠀findField(ast, definitionName, fieldName) → {Object|null}
Iterate through the fields of a definition AST if there are any. For each
field, the name property's value field is compared to the supplied
fieldName. The fieldName can be a string or a regular expression if
finer granularity is desired.
Before iterating over the fields, however, the definition is found usingSyntaxTree#findDefinition
. If either the field or definition are not
found, null is returned.
- Since:
- 2.7.0
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object
|
an abstract syntax tree object created from a GQL SDL |
definitionName |
string
|
RegExp
|
a string or regular expression used |
fieldName |
string
|
RegExp
|
a string or regular expression used |
Returns:
- Type:
-
Object
|null
an object containing two keys, the first beingfield
which points to the requested AST definition field. The second
being meta
which contains three commonly requested bits of data; name
,type
and nullable
. Non-nullable fields have their actual type wrapped
in a NonNullType
GraphQL construct. The actual field type is contained
within. The meta object surfaces those values for easy use.
(static) ⌾⠀findInASTArrayByNameValue(array, name) → {Object|null}
A lot of searching in ASTs is filtering through arrays and matching on
subobject properties on each iteration. A common theme is find something
by its .name.value
. This method simplifies that by taking an array of
AST nodes and searching them for a .name.value
property that exists
within.
- Since:
- 2.7.0
- Source:
Parameters:
Name | Type | Description |
---|---|---|
array |
Array
|
of mixed AST object nodes containing |
name |
string
|
RegExp
|
a string or regular expression used |
Returns:
- Type:
-
Object
|null
the AST leaf if one matches or null otherwise.
(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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
mixed |
String
|
Object
|
SyntaxTree
|
an instance of one of the valid |
Returns:
- Type:
-
SyntaxTree
a newly created and populated instance of SyntaxTree
or null if an invalid type was supplied for mixed.
(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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
object
|
a valid GraphQL AST object. |
Returns:
- Type:
-
SyntaxTree
a new instance of SyntaxTree initialized with a
supplied abstract syntax tree generated by require('graphql').parse() or
other compatible method.
(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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schema |
string
|
a valid GraphQL IDL schema string. |
Returns:
- Type:
-
SyntaxTree
a new instance of SyntaxTree initialized with a
parsed response from require('graphql').parse().
(static) ⎆⠀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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string
|
Object
|
SyntaxTree
|
if supplied the tree |
⌾⠀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).
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schemaOrASTOrST |
string
|
Object
|
SyntaxTree
|
an instance of one of |
⌾⠀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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
astOrSyntaxTree |
Object
|
SyntaxTree
|
a valid GraphQL IDL AST or |
definitionType |
string
|
RegExp
|
a valid search input as would be |
⌾⠀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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
definitionName |
string
|
RegExp
|
a string or regular expression used |
Returns:
- Type:
-
Object
|null
a reference to the internal definition field or
null if one with a matching name could not be found.
⌾⠀findEnumDefinition(ast, enumDefinitionName, enumValueName) → {Object|null}
Enum AST definitions operate differently than object type definitions
do. Namely, they do not have a fields
array but instead have a values
array. This wrapper method, first finds the enum definition in the ast
and then searches the values for the named node desired and returns that
or null, if one could not be found.
- Since:
- 2.7.0
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object
|
the abstract syntax tree parsed by graphql |
enumDefinitionName |
string
|
RegExp
|
a string or regular expression |
enumValueName |
string
|
RegExp
|
a string or regular expression used |
Returns:
- Type:
-
Object
|null
the desired AST node or null if one does not exist
⌾⠀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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
schemaOrAST |
string
|
Object
|
a valid GraphQL IDL schema or a |
⌾⠀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.
- Source:
Returns:
- Type:
-
string
the AST for the tree parsed back into a string
⌾⠀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.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
ast |
Object
|
an existing GraphQL IDL AST object that will be |
⬆︎⠀ast(value)
Setter that assigns the abstract syntax tree, typically created bygraphql.parse
when given a valid string of IDL.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
value |
Object
|
a valid AST object. Other operations will act |
⬇︎⠀ast() → {Object}
Getter that retrieves the abstract syntax tree created by graphql.parse
when it is presented with a valid string of IDL.
- Source:
Returns:
- Type:
-
Object
a GraphQL AST object