You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to check for some permission before user subscribe to an endpoint. An error should be thrown and the client should be able to catch the error.
The following is what I am trying:
someSubscriptionEndpoint: {
subscribe: (payload, args, context, info) => {
throw new Error('Internal server error');
}
}
But the error I receive on client side is "Subscription field must return Async Iterable. Received: [object Object]"
This line is called twice, the first time eventStream is the error I threw so condition is true and the error is wrapped and rethrown. The second time I received { errors: [ [GraphQLError] ] } and the the error in line 281 is thrown.
What is the correct way of throwing an error when client subscribes to an specific subscription endpoint?
The text was updated successfully, but these errors were encountered:
The subscribe method is not the resolver for the field. There is a separate resolve method you can specify that works exactly like the resolver for any other field.
Note that the root value will be whatever value was published. So you can publish any value and use the resolver to transform it. For example, instead of publishing an entire object, you could just publish the id and the resolve the field based on that.
/label question
I would like to check for some permission before user subscribe to an endpoint. An error should be thrown and the client should be able to catch the error.
The following is what I am trying:
But the error I receive on client side is
"Subscription field must return Async Iterable. Received: [object Object]"
https://github.com/graphql/graphql-js/blob/master/src/subscription/subscribe.js#L272
This line is called twice, the first time eventStream is the error I threw so condition is true and the error is wrapped and rethrown. The second time I received
{ errors: [ [GraphQLError] ] }
and the the error in line 281 is thrown.What is the correct way of throwing an error when client subscribes to an specific subscription endpoint?
The text was updated successfully, but these errors were encountered: