graphql-client
graphql-client copied to clipboard
How would you use Fragments?
Is there a support to use reusable fragments with this client? As far as I tested, I can use fragments this way:
@" query ($ids: [UUID!]!) { companiesByIDs (ids: $ids) { address iD ...FragmentMetadata name } } fragment FragmentMetadata on Company { metadata{ createdBy createdOnUTC dataVersion modifiedBy modifiedOnUTC schemaVersion } }
But if I have to define them in each query string, then they are pointless and not reusable?
There is no "out-of-the-box" support for this.
But I think you could build something like this by making a dedicated GraphQLHttpRequest class, which always appends all your predefined fragments to the query string (or maybe just the ones actually used in the query)...
If you can make that reusable, I'll happily accept a PR 😉
You may search for some GraphQL generators. Such generators usually have more or less strict APIs in generated code for fields/operations/arguments/etc. For a long time I am using a GraphQL generator of my own at work. It supports reusing fragments. Unfortunately, it's a private repository. The reason is not so much in the rights to intellectual property as in the lack of time and effort to open its code, add tests / CI / documentation and so on.