You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It might be interesting to change the way queries are parsed and validated.
Currently we use the libgraphqlparser to browse the nodes of the query using callback functions that are called each time the parser encounters a new node in the document. At each node encountered the callback function generates a VisitorElement object which is then passed when calling the update method of the Visitor instance which is responsible of business logic (validation, addition of information to the visitor context, creation of Node object...).
These different processes are complex and long to execute. The addition of the management of new errors gradually make the code less and less readable and more difficult to maintain.
To tackle this problem, we could dissociate this unique treatment into separate steps:
Parse the query to generate a DocumentNode object containing all the information related to the query.
This step can be easily done by calling the graphql_ast_to_jsonlibgraphqlparser function which analyzes the query and returns a string in JSON format containing all the information related to the query. This string could then be computed into a DocumentNode object.
Apply the set of validation rules defined by the GraphQL specification to this DocumentNode object.
Proceed in this way to several advantages:
Allow to cache for each query the generation of the DocumentNode and the application of validation rules.
Delete a lot of code (Visitor, VisitorContext & most of the code contained in cffi parser) and gain in simplicity/readability/maintainability.
Have a DocumentNode object conforming to the GraphQLlanguage specifications. This would allow to be more faithful to the specifications but also to facilitate the on-boarding of new collaborators.
Be closer to the specification and allow to deal with some particular case still poorly managed currently (such as the merge of SelectionSet).
TODO
Implements functions which parse a SDL or query string to a DocumentNode instance
Cache SDL/query parsing & validation
Use DocumentNode to build schema
Use DocumentNode to execute query
The text was updated successfully, but these errors were encountered:
It might be interesting to change the way queries are parsed and validated.
Currently we use the
libgraphqlparser
to browse the nodes of the query using callback functions that are called each time the parser encounters a new node in the document. At each node encountered the callback function generates aVisitorElement
object which is then passed when calling theupdate
method of theVisitor
instance which is responsible of business logic (validation, addition of information to the visitor context, creation ofNode
object...).These different processes are complex and long to execute. The addition of the management of new errors gradually make the code less and less readable and more difficult to maintain.
To tackle this problem, we could dissociate this unique treatment into separate steps:
DocumentNode
object containing all the information related to the query.This step can be easily done by calling the
graphql_ast_to_json
libgraphqlparser
function which analyzes the query and returns a string inJSON
format containing all the information related to the query. This string could then be computed into aDocumentNode
object.DocumentNode
object.Proceed in this way to several advantages:
DocumentNode
and the application of validation rules.Visitor
,VisitorContext
& most of the code contained incffi
parser) and gain in simplicity/readability/maintainability.DocumentNode
object conforming to theGraphQL
language specifications. This would allow to be more faithful to the specifications but also to facilitate the on-boarding of new collaborators.SelectionSet
).TODO
DocumentNode
instanceDocumentNode
to build schemaDocumentNode
to execute queryThe text was updated successfully, but these errors were encountered: