graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

Instruct all graphiql/toolkit users to install graphql-ws

Open eMerzh opened this issue 2 years ago ā€¢ 12 comments

seems it breaks my builds with

Module not found: Error: Can't resolve 'graphql-ws' in '/proj/node_modules/@graphiql/toolkit/esm/create-fetcher'

i don't use graphql-ws directly but the fetcher as described in doc

import { createGraphiQLFetcher } from '@graphiql/toolkit'

const fetcher = createGraphiQLFetcher({
	url: '/graphql',
})

would pin point the breakage here https://github.com/graphql/graphiql/commit/c36504a804d8cc54a5136340152999b4a1a2c69f BC graphql-ws was included by graphql-config which is not true anymore?

Thanks for the work here :)

eMerzh avatar Apr 19 '22 07:04 eMerzh

graphql-ws is a peer dependency if you check the readme. if we marked a specific version of graphql-ws in dependencies it would break people's implementations

acao avatar Apr 19 '22 07:04 acao

@enisdenjo do you think we should just depend on the latest version of graphql-ws, or keep graphql-ws as a peer dep?

acao avatar Apr 19 '22 07:04 acao

it's less than ideal that non-wss users have to install it for our fetcher, though. perhaps we can re-architect the createGraphiQLFetcher to allow "plugins", just worried that would send us down a path of complexity.

@dotansimha and @timsuchanek what do you think?

acao avatar Apr 19 '22 07:04 acao

I'd suggest leaving it as a peer dep, absolutely no need to push a new version of @graphiql/toolkit everytime graphql-ws updates.

enisdenjo avatar Apr 19 '22 07:04 enisdenjo

so i should include it in my package.json even though i don't use it directly?

eMerzh avatar Apr 19 '22 07:04 eMerzh

@eMerzh for now, yes, sorry. this is generally the case for all peerDependencies of graphiql. we may be able to re-architect the toolkit to accomodate non-wss users

acao avatar Apr 19 '22 07:04 acao

šŸ‘Œ thanks for the help šŸ‘

it would probably help to make it as explicit code dependancy like in examples with createGraphiQLFetcher using a "simple" client ... to make it clearer. anyway, you can close this if you want :)

eMerzh avatar Apr 19 '22 08:04 eMerzh

I'd also say we keep it as a peer dependency for now, but then revisit this topic once we're looking at a more elaborate plugin system targeting v2.

timsuchanek avatar Apr 19 '22 08:04 timsuchanek

I'll close this for now, as it seems to be resolved in this case.

timsuchanek avatar Apr 19 '22 08:04 timsuchanek

Iā€™m reopening until we resolve this ticket by updating the docs at least.

@eMerzh agreed, I think we need to update several markdown files with these instructions

acao avatar Apr 19 '22 09:04 acao

Related: https://github.com/graphql/graphiql/issues/2405

thomasheyenbrock avatar May 16 '22 16:05 thomasheyenbrock

I found a much better solution to this problem!

peerDependenciesMeta allows you to specify which peer dependencies are optional

acao avatar May 31 '22 10:05 acao

The latest version (@graphiql/[email protected]) now specifies graphql-ws as optional peer dependency

thomasheyenbrock avatar Sep 07 '22 07:09 thomasheyenbrock