graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

How would you use Fragments?

Open PatrickBateman91 opened this issue 3 years ago • 2 comments
trafficstars

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?

PatrickBateman91 avatar Sep 06 '22 10:09 PatrickBateman91

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 😉

rose-a avatar Sep 06 '22 17:09 rose-a

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.

sungam3r avatar Sep 19 '22 14:09 sungam3r