-
Beta Was this translation helpful? Give feedback.
Answered by
enisdenjo
Feb 10, 2023
Replies: 1 comment
-
Hey there, I am not an Apollo expert but I can help out with the graphql-ws part. The reason why the whole connection closes is because graphql-ws server treats all errors thrown from hooks as fatal and unexpected. If you want to stop/error-out only one specific subscription, both client and server side, you should return an array of async onSubscribe({ extra }, msg) {
let query: string;
const pqh = msg.payload.extensions?.persistedQuery as { sha256Hash: string; version: string };
if (pqh) {
query = await cache.get(`apq:${pqh.sha256Hash}`);
if (!query) {
- throw new PersistedQueryNotFoundError();
+ return [new GraphQLError('Persisted query not found')]
}
}
const args = {
document: parse(query ?? msg.payload.query),
... Since the error gets serialised when sent to the client, it doesn't really matter what type of it is. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
enisdenjo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there, I am not an Apollo expert but I can help out with the graphql-ws part.
The reason why the whole connection closes is because graphql-ws server treats all errors thrown from hooks as fatal and unexpected. If you want to stop/error-out only one specific subscription, both client and server side, you should return an array of
GraphQLError
s fromonSubscribe
instead.