Skip to content

Commit

Permalink
graphql subscriptions testing done
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancy Goyal committed Jan 2, 2018
1 parent e958f61 commit bcddbb2
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions schema/gql/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { withFilter } from 'graphql-subscriptions';
import { registerUser, loginUser, logoutUser } from '../../controllers/user';
import pubsub from '../../utilities/subscriptions';
import logger from '../../utilities/logger';

const SOMETHING_CHANGED_TOPIC = 'something_changed';

export const typeDefs = `
type User {
Expand Down Expand Up @@ -45,23 +49,23 @@ export const resolvers = {
loginUser,
logoutUser,
newUser(root, payload, context) {
pubsub.publish('something_changed', { newUser: 'newUser' });
return 'newUser';
pubsub.publish(SOMETHING_CHANGED_TOPIC, { newUser: 'Dev' });
return 'Dev';
}
},
Subscription: {
newUser: {
subscribe: () => pubsub.asyncIterator('something_changed'),
resolve: payload => {
return payload.newUser;
}
// subscribe: withFilter(
// () => pubsub.asyncIterator('newUser'),
// (root, args, context) => {
// logger.log('newUser subscribe', args, context);
// return true;
// }
// )
// subscribe: () => pubsub.asyncIterator('something_changed'),
// resolve: payload => {
// return payload.newUser;
// },
subscribe: withFilter(
() => pubsub.asyncIterator(SOMETHING_CHANGED_TOPIC),
(root, args, context) => {
logger.info('newUser', context);
return true;
}
)
}
}
};

0 comments on commit bcddbb2

Please sign in to comment.