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

Fragments used in Fragments are leading to big source.body string

Open marvinsemmelroth opened this issue 1 year ago • 1 comments
trafficstars

Originally opened in https://github.com/graphql/graphql-js/issues/4255 but the conclusion was that the implementation should happen here.

To recap:

The problem im facing is that when using graphql-tag im seeing huge memory chunks taken up by the query-strings (as far as 2.5mb) especially when using a lot of fragments.

The cause of this is this concat https://github.com/apollographql/graphql-tag/blob/main/src/index.ts#L125-L132 which will concat all used fragments into the to be parsed string which if you have alot of fragments result into a large string.

As proposed by @JoviDeCroock here I'd like to see the change that we reuse already declared definitions by merging them into the parsed document rather than parsing the definitions again (and again). In my local testing this would free up a lot of space both for the source and also for the docCache-Key and also should improve performance by just using the existing definitions rather than parsing them again.

marvinsemmelroth avatar Oct 25 '24 13:10 marvinsemmelroth