diff --git a/graphql/resolvers.js b/graphql/resolvers.js index 3714d37..4c69222 100644 --- a/graphql/resolvers.js +++ b/graphql/resolvers.js @@ -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, @@ -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; }, @@ -98,6 +102,8 @@ const resolvers = { anon = false; } + pubsub.publish("USER_STATUS_CHANGED", { userId: user.id, user }); + return jwt.sign( { "https://beacon.ccextractor.org": { @@ -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 + ), + }, }, }), }; diff --git a/graphql/schema.js b/graphql/schema.js index c0d0662..2948cde 100644 --- a/graphql/schema.js +++ b/graphql/schema.js @@ -129,6 +129,7 @@ const typeDefs = gql` userLocation(id: ID!): User beaconJoined(id: ID!): User groupJoined(groupID: ID!): User + userStatusChanged(userId: ID!): User } schema {