Skip to content

APQ support with ApolloServer #445

Answered by enisdenjo
intellix asked this question in Q&A
Discussion options

You must be logged in to vote

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 GraphQLErrors from onSubscribe instead.

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('…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by enisdenjo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants