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

Created a subscription to check when a user's status change #379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const Group = require("../models/group.js");
const Landmark = require("../models/landmark.js");
const { User } = require("../models/user.js");
const { MongoServerError } = require("mongodb");
const pubsub = require("../pubsub.js");

const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// even if we generate 10 IDs per hour,
Expand Down Expand Up @@ -73,7 +74,10 @@ const resolvers = {
password: await bcrypt.hash(credentials.password, 10),
}),
});

const userObj = await newUser.save();
pubsub.publish("USER_STATUS_CHANGED", { userId: user.id, user });

return userObj;
},

Expand All @@ -98,6 +102,8 @@ const resolvers = {
anon = false;
}

pubsub.publish("USER_STATUS_CHANGED", { userId: user.id, user });

return jwt.sign(
{
"https://beacon.ccextractor.org": {
Expand Down Expand Up @@ -314,6 +320,12 @@ const resolvers = {
(payload, variables) => payload.groupID === variables.groupID
),
},
userStatusChanged: {
subscribe: withFilter(
(_, __, { pubsub }) => pubsub.asyncIterator(["USER_STATUS_CHANGED"]),
(payload, variables) => payload.userId === variables.userId
),
},
},
}),
};
Expand Down
1 change: 1 addition & 0 deletions graphql/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const typeDefs = gql`
userLocation(id: ID!): User
beaconJoined(id: ID!): User
groupJoined(groupID: ID!): User
userStatusChanged(userId: ID!): User
}

schema {
Expand Down