enisdenjo / graphql-ws

Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
https://the-guild.dev/graphql/ws
MIT License
1.75k stars 162 forks source link

Cannot return null for non-nullable field Subscription.greeting #459

Closed jmc420 closed 1 year ago

jmc420 commented 1 year ago

I am getting "Cannot return null for non-nullable field Subscription.greeting" returned to Postman when I invoke a subscription:

Schema looks like this:

const gql = `
    type Query {
        sayHello: String!
      }

      type Mutation {
        sendMessage(message:String!):String !
      }

      type Subscription {
          greeting: String!
      }
    `;

The resolver looks like this:

const rootValue = {
    subscription: {
        greeting: async function* () {
            for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
                yield { greetings: hi };
            }
        }
    }
}

The full code of the example can be found here:

https://github.com/jmc420/graphql_examples/blob/main/graphql-ws/src/server.ts