Hey, i am trying to do a subscription but got erro...
# prisma-whats-new
v
Hey, i am trying to do a subscription but got error "Cannot read property 'subscribeToMore' of undefined" can someone help?
n
@vacom Some code would help 😛
v
I am doing this on componentDidMount this.createMessageSubscription = this.props.channelQuery.subscribeToMore({ document: gql` subscription newMessages { Message(filter: {mutation_in: [CREATED]}) { mutation node { channel(filter: {id: "cj0pl8mg0t8300177zo0ib9ry"}) { id messages { id content createdAt author { id profile { name picture } } } } } } } `, updateQuery: (previousState, {subscriptionData}) => { console.log(subscriptionData.data); }, onError: (err) => console.error(err), });
n
can you show how you use the graphql wrapper to inject the channelQuery?
v
export default graphql(channelQuery, { options: {forceFetch: true }})(withRouter(MessagesContainer))
n
either change this
this.createMessageSubscription = this.props.channelQuery.subscribeToMore({
to
this.createMessageSubscription = this.props.data.subscribeToMore({
or supply the
name
option to the
graphql
to set the name of the query to
channelQuery
🙂
v
Thanks a lot, now I'm having permissions errors my app has to be authenticated, in the simple endpoint everything was going fine but I do not know if I'm going through correctly in the subscriptions, could I see if the following code is correct? const wsClient = new SubscriptionClient('wss://subscriptions.graph.cool/v1/_Project_', { reconnect: true, connectionParams: { authToken: localStorage.getItem('graphcoolToken'), }, });
n
I believe using
connectionParams
like that will only set the auth token the first time, when it's still
null
I think you would need to use
onSubscribe
, as described here: https://github.com/apollographql/subscriptions-transport-ws#constructoroptions-socketoptions
v
i am trying to figure it out
but thank you a lot for the help
i still get the Code 3008: InsufficientPermissions, is there any instructions on graphcool documentations about this ?
n
Can you verify that the auth token is included in the subscription request?
if it's not included that's the problem and is likely related to what we discussed above
v
yes i think so, i see the graphcool_auth_token on the request on the network
But in your demo of World Chat, that configuration is because the content is public right?
n
do you see it also on the subscription request? you can make sure by choosing the WS filter in the network tab (chrome)
yep the example is about public data
v
is this one?
i am working on localhost do i have to configure something on the graphcool dashboard?
n
yes that's the correct url and no nothing special is needed for that
v
I thing is working now, no more permissions errors
n
then could you paste your subscription here?
hmm ok, what did you change?
v
i changed to this connectionParams: { Authorization:
Bearer ${localStorage.getItem('graphcoolToken')}
, }, now is getting the data
n
yea so could you try it again in an incognito tab?
v
yes is working in incognito