question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undefined error if Subscription starts with capital letter in roots

See original GitHub issue

Screenshot

image

Expected Behaviour

There should not be an error if Subscription is used in roots.

Actual Behaviour

There is an undefined error if Subscription starts with a capital letter. When using graphql server and graphql-tools, there is no such error 🤔

Debug Information

From docs, capitalize subscription first letter:

roots: {
  Subscription: {
    greetings: async function* sayHiIn5Languages() {
      for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
        yield { greetings: hi }
      }
    }
  }
}

Further Information

Trying to move from deprecated subscriptions-transport-ws 🙈

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
enisdenjocommented, Jun 16, 2021

Yeah, there should be a more communicative error message there… I guess an issue for Altair. Thanks for sharing!

My suggestion on auth is in the “ws server and client auth usage with token expiration, validation and refresh” recipe. Do check it out. 😄

1reaction
enisdenjocommented, Jun 16, 2021

The roots object expects lowercase operation names. Please read the documentation about the roots option.

On how the roots work, the detected operation type root is put directly in the execute/subscribe rootValue argument: https://github.com/enisdenjo/graphql-ws/blob/4f11c8aeec092fac21bee6c9084f1e622b5e4a41/src/server.ts#L716

Furthermore, the roots option is just a convenience. You should absolutely use only the schema option as you attempted. However, when using makeExecutableSchema, you must nest the subscriptions iterator under the subscribe path:

const resolvers = {
  Subscription: {
-    greetings: async function* sayHiIn5Languages() {
-      for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
-        yield { greetings: hi }
-      }
-    }
+    greetings: {
+      subscribe: async function* sayHiIn5Languages() {
+        for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
+          yield { greetings: hi }
+        }
+      }
+    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Subscription of observable returns undefined - Stack Overflow
I use a service to fill my observable with data from the backend. The backend is delievering the correct data. Now I want...
Read more >
Complete Vue Router 4 Guide: Basics, Programmatic Routing ...
All undefined and illegal routes will be handled by the last routing rule. Next, we create an error component. We make a copy...
Read more >
How To Use Bash Parameter Substitution Like A Pro - nixCraft
Explains how to use Bash Parameter Substitution for string matriculation and expansion - includes tons of practical examples.
Read more >
GraphQL specification
A schema defines the initial root operation type for each kind of operation it supports: query, mutation, and subscription; this determines the place...
Read more >
Migrating to Apollo Server 4 - Apollo GraphQL Docs
A set of core plugins (similar to Apollo Server 3's apollo-server-core package). There are no integration-specific subclasses in Apollo Server 4. Instead, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found