Closed gyzerok closed 8 years ago
Also it would be nice to have check
function to be able to check query against schema to know if it is valid.
+1
They expose parser and AST visitor as public API and you can import parse
and visit
from graphql/language. Parse will give you Abstract Syntax Tree that you can walk through with visit
. In-code documentation for visitor is great (see language/visitor.js), but post if you have any questions.
Finally, you can import validate
and specifiedRules
from graphql/validation and run query AST and schema definition through it to make sure everything is copacetic.
As far as query optimization goes, I defer to graphql team, but wouldn't think it make sense to have that in the reference implementation. It is perhaps a layer you have in between GraphQL endpoint and data store that caches and consolidates redundant queries, see Haxl for inspiration.
It would be cool if you can provide functionality for parsing, merging and compiling GraphQL queries. So not only Relay can use awesome features of GraphQL.
parse
function should parse GraphQL query string into structure likeinfo
object which you can get inresolve
function.compile
function should be an opponent forparse
merge
function should merge twoinfo
objects to later perform optimised query to the server.Consider this example:
Using suggested functions it can be merged in: