Closed imjasonmiller closed 1 year ago
This is indeed a bug. I think it could be fixed inside handleSubscription.ts
something like this:
const normalizedQuery = normalizeQuery(operation.query);
if (!normalizedQuery) {
throw new Error('A query must be provided.');
}
useResult(forward({ ...operation, query: normalizedQuery }) as any, true);
Feel free to PR, otherwise, I will PR it tomorrow since it looks like a serious bug for non apollo-server users and breaks compact with other protocol libs.
EDIT: Really wanted you to have a go at this but I think this is a bug that needs to be fixed ASAP, many thanks for pointing it out and love the way you explained it. Thanks again!
Hey, great library!
Perhaps I am holding it wrong, but I was caught by surprise by the documentation mentioning that queries parsed with
gql
fromgraphql-tag
can be passed touseQuery
, while this seems to work a bit different foruseSubscription
.While the API reference states a
DocumentNode
can be passed as well, I received that exactDocumentNode
within thesubscriptionForwarder
by setting it up as described by the guide. It looks like that will result in an error forgraphql-ws
's client as it takes astring
and no normalization is performed, unlikeuseQuery
.Is this intended behavior or would it be possible to apply the normalization to
query
foruseSubscription
as well and/or expose thenormalizeQuery
function so it can be easily used within thesubscriptionForwarder
as well?I'd gladly open a pull request, if so.
Thanks!