As part of our work to migrate our main website to a GraphQL back-end we created some code that we felt that others could find useful too.
We wanted to run few GraphQL queries, but at the same time want every (React) component on the page to be able to specify its own data needs. We knew Relay does something like this, but we’re not using Relay. Thus we came up with createFragment(), where components specify the fields they use, and createQuery(), where a top-level component can easily combine those fragments into a valid query.
Those functions are now packaged into the graphql-defragmentizer library, which we just released as Open Source. The code, with examples, can be found at https://github.com/SVT/graphql-defragmentizer.
It’s under the MIT license, so feel free to contribute!