nanographql
nanographql copied to clipboard
Caching, fetching and inspection
This is quite the rewrite and I'm fully aware it may not be well received. I was about to create something along the lines of nanographql before I knew it even existed. But as I started looking into parsing GraphQL queries with RegExp I realized we can do much more than just deriving the operation name. This did however bring a significant increase in size, from 15 LOC to ~200, so it may not be legitimately "nano" anymore.
Since I'm not currently a user of nanographql I'd really appreciate some feedback from people using it. If the changes are not welcome I'll just publish it under a different name. Alternately, the cache and fetching bits could be split out to another package, e.g. choo-graphql
or something. However, these changes do address all issues and PRs currently open in this project.
These changes address:
- Expressions: strings, and even other queries (fragments), can be interpolated to create dynamic queries (#1)
- Inspection: the return value from a query is an object with methods to serialize it in many different ways (
toString
,toJSON
) and even iterate over its properties (#7) - Fragments: fragments are supported and can even be interpolated from other queries (#8)
- Caching: results are cached per query, which allows for maintaining state between queries and mutations (#11)
- Update standard: standard recently introduced the
no-var
rule in a major update
See README for complete documentation of new functionality.