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.

Unhandled GraphQL subscription error Error: GraphQL error: Cannot return null for non-nullable field Subscription.teamCreated

See original GitHub issue

I’m pulling my hair out with this issue…

I’m using this component:

<ListAllTeamsData
    data={data}
    subscribeToMoreTeams={() => {
        subscribeToMore({
            document: LIST_ALL_TEAMS_SUBSCRIPTION,
            updateQuery: (previousResult, { subscriptionData }) => {
                console.log(previousResult, subscriptionData)
                if (!subscriptionData.data) {
                    return previousResult
                }

                const { teamCreated } = subscriptionData.data

                return {
                    ...previousResult,
                    teams: [
                        ...previousResult.teams,
                        teamCreated.team
                    ],
                }
            },
        })
    }}
/>

And the scema:

export const LIST_ALL_TEAMS_SUBSCRIPTION = gql`
    subscription {
        teamCreated {
            team {
                name
                id
                status
                mobile
            }
        }
    }
`

It works fine when I run the subscription in the GraphQL playground, but I get the error in the app. I have no idea why. Any help? It won’t even hit the console.log so there seems to be something wrong with ‘document: LIST_ALL_TEAMS_SUBSCRIPTION’, but from what I can tell it’s all fine.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakec-devcommented, Mar 12, 2019

So the solution was simple. I just changed the server schema so that the return value from the subscription isn’t required.

E.g. from https://github.com/the-road-to-graphql/fullstack-apollo-express-postgresql-boilerplate/blob/master/src/schema/message.js

- line 32: messageCreated: MessageCreated!
+ line 32: messageCreated: MessageCreated

OK to close. Thanks.

0reactions
rwieruchcommented, May 14, 2019

Anyone who runs into this issue, please leave a comment. Otherwise I will close it the next time I come around here 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL error: Cannot return null for non-nullable ... - GitHub
Unhandled GraphQL subscription error Error: GraphQL error: Cannot return null for non-nullable field Subscription.teamCreated #4568.
Read more >
"Cannot return null for non-nullable field" when subscribing on ...
With all this, my frontend gives me an error ERROR Error: GraphQL error: Cannot return null for non-nullable field Subscription.scoreAdded.
Read more >
Issue in "Exploring our first query" - Help - Apollo GraphQL
While trying to run the first tracksForHome query, I get the below error: { "errors": [ { "message": "Cannot return null for non-nullable...
Read more >
Cannot return null for non-nullable type graphql - Fauna Forums
I get the following error when i query allTodos index through graphql "errors": [ { "message": "Cannot return null for non-nullable type ...
Read more >
cannot return null for non-nullable field - You.com
graphql.errors.handled A query had an error [PID:33:MainThread] web_1 | Traceback ...
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