In our previous article, we only talked about the basic query and how it is being parsed to build an AST object.
In this article, we are going to understand how variables, directives, and parameters are being parsed.
Consider the following query,
Here we added the variables,
$after that is a
$includeUsername that is a non-nullable
In our previous query, the
variableDefinitionswas an empty array. But for this case, it will be not. Variable can only be defined on the operations.
For each variable being defined, there will be a corresponding single entry in the
variableDefinitions. Each object has the following properties:
kind- which will always be a
variable- This provides the information of the variable, it contains the name of the variable and its type.
type- Defines the type of the variable. The interesting part is that, when the variable is not nullable, it’s
$includeUsername: Boolean!), then on the
typeproperty where we get the type that is non-nullable, unlike from nullable type, its
typewill be defined on the property, with
defaultValue- Provides the information of the default value.
directive- Provides the information of the directives.
In the query above we included the directive
if on the
id that has a parameter and a variable as the parameter value.
Directives can be present in the operation, field, and variables. In the query, the directive is being added to the field
For each entry in the
directives the property they all have the same fields, namely the kind, name, and arguments.
kind- This will always be a
name- Holds the information of the name of the field.
arguments- Holds the information of the arguments being passed on the directive
Based on the query above, there are 2 parts that the argument was present, the first one is from the directives and the second one was on the
These arguments are on the
addresses field selection. We have declared 2 kinds of arguments the one was a value and the other one was the variable.
Stay tuned for more updates as we continue to understand how fragments are being parsed.