mercurius icon indicating copy to clipboard operation
mercurius copied to clipboard

Reduce package dependencies

Open p-kuen opened this issue 2 years ago • 3 comments

I installed mercurius the first time today and I recognized it has a lot of dependencies which could be reduced quite easily in my opinion:

promise.allsettled:

As of NodeJS 12.9 and up Promise.allsettled is available natively without a package dependency. If there would be a node minimal version of 12.9 set, we could remove this dependency (especially because this package has a lot of polyfill dependencies too)

events.on:

As of NodeJS 12.16 and up events.on is available natively without a package dependency. If there would be a node minimal version of 12.16 set, we could remove this dependency

ws and fastify-websocket

It is sad that everyone who does not use the websocket feature has to install these dependencies. In my opinion it would be better if this feature is a plugin for mercurius.

graphql-jit

In my case, I am using code-first graphql (no gql language used). Therefore I don't need graphql-jit, yet I have the dependency installed and even get a peer dependency error because I am using graphql >= 16. I would recommend using graphql-jit as a plugin.

readable-stream

I do not exactly know as of which version of NodeJS readableStreams are supported, but I am sure, most of the users of mercurius do not need this polyfill.

undici

In the code I identified undici to be used for gateways. It would be perfect, if this was a plugin for mercurius too as I think most users do not use this feature.

I would be glad to help reducing dependencies of this package. :)

p-kuen avatar Feb 06 '22 14:02 p-kuen

If you would like to send PRs for promise.allsettled and events.on, it would be amazing.

As for graphql-jit, it seems it is not clear to you how it works. It will improve the performance of your queries independently on how you generate the schema. The peerDep warning does not affect the actual operations and it will soon be fixed. It's great to keep it where it is.

readable-stream is not removable as it will be installed by other dependencies too.

As for the gateway and websockets, they are not that easy to remove and it would severely complicate the maintenance of this module. Extracting them as plugins is possible - but we would have to shift this repo to a monorepo as they are fundamental part of this module. If you'd like the challenge, I'll be happy to review a PR.

mcollina avatar Feb 06 '22 15:02 mcollina

@p-kuen any progress on this?

simoneb avatar Jul 11 '22 15:07 simoneb

My PR for promise.allsettled was already merged and released, events.on would be my next try. Will do that soon!

p-kuen avatar Jul 11 '22 18:07 p-kuen

I'll remove events.on

marco-ippolito avatar Nov 28 '22 16:11 marco-ippolito

@mcollina are there any other packages from this issue that could be worth trying to remove?

marco-ippolito avatar Nov 29 '22 14:11 marco-ippolito

I think extracting federation & gateway will reduce the size significantly.

mcollina avatar Dec 01 '22 19:12 mcollina

This would be amazing but quite a huge challenge. @mcollina You thought about a monorepo, right? Would it be possible to create a separate repo as a plugin for mercurius?

p-kuen avatar Dec 02 '22 08:12 p-kuen

Here is it: https://github.com/mercurius-js/mercurius/pull/916.

@codeflyer is on it.

mcollina avatar Dec 02 '22 08:12 mcollina

If we have removed all the external deps that we wanted to remove, and since the gateway is already in a different repo, shall we consider closing this issue then?

simoneb avatar Dec 02 '22 08:12 simoneb

yes

mcollina avatar Dec 02 '22 22:12 mcollina