apollographql / graphql-subscriptions

:newspaper: A small module that implements GraphQL subscriptions for Node.js
MIT License
1.59k stars 133 forks source link

[object Object] Result when doing pubsub.publish #96

Closed ralphchristianeclipse closed 7 years ago

ralphchristianeclipse commented 7 years ago

The problem is when publishing a value it will return null on the subscribe method

export const subscriptions = model => ({
    [model]: {
        resolve(payload) {
            console.log({...payload[model]})
            return {...payload[model]}  
        },
        subscribe: withFilter(() => pubsub.asyncIterator(
            ['CREATED','UPDATED', 'DELETED']
            .map(mutation => `${model.toUpperCase()}_${mutation}`)),
            (payload,variables) => {
                return payload.id === variables.id
            })
    }
})

And publishing it like this

    [`update${model}`]: async(_, { id, ...args }, { models }, info) => {
        let result = await models[model].findById(id)
        await result.update(args)
        pubsub.publish(`${model.toUpperCase()}_UPDATED`, {
            [model]: args
        })

        return result
    },

this is what i get received from the Subscription resolve

[nodemon] starting `babel-node src`
Server started at 0.0.0.0:8080
express deprecated req.host: Use req.hostname instead src/server.js:97:88
{ name: 'testerssas',
  description: 'test',
  slug: 'testerssas',
  fee: 0 }
POST /graphql 200 59.101 ms - -

and getting this error

image

Noticed that [object Object] is an error

ralphchristianeclipse commented 7 years ago

I think the problem is not returning an id on the publish but doing rather sending the args