Unhandled GraphQL subscription error Error: GraphQL error: Cannot return null for non-nullable field Subscription.teamCreated
See original GitHub issueI’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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
OK to close. Thanks.
Anyone who runs into this issue, please leave a comment. Otherwise I will close it the next time I come around here 😃