Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jakec-dev opened this issue Mar 10, 2019 · 5 comments

Comments

@jakec-dev
Copy link

jakec-dev commented Mar 10, 2019

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.

@jakec-dev
Copy link
Author

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.

@rwieruch
Copy link
Member

How did you come to this conclusion? Didn't know that the return value shouldn't be required. Do you think it's something Apollo specific?

@jakec-dev
Copy link
Author

I'm still confused about it. Like I said, the schema runs fine in graphql playground so I shouldn't have had to adjust the server schema - it must be an issue on the client side. Yet it's the exact same client-side schema being used so it should be working.

I'm using React hooks so it may have something to do with the useEffect hook vs componentDidMount (where props.subscribeToMoreTeams() is called). That's the only other thing I can think of.

@rwieruch
Copy link
Member

Let's keep the issue open in case someone else runs into it. Would be curios what's the cause of this, so maybe someone has the answer or we stumble upon the solution eventually :) Thanks for your time! 👍

@rwieruch
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants