Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const chat = await group.getChat();
return Boolean(chat.id === payload.messageAdded.chatId);
},
),
},
groupAdded: {
subscribe: withFilter(
() => pubsub.asyncIterator(GROUP_ADDED_TOPIC),
(payload, args) => {
// console.log(JSON.stringify(payload, null, 2));
return Boolean(true /*args.userId === payload.groupAdded.userId*/);
},
),
},
messageInGroupAdded: {
subscribe: withFilter(
() => pubsub.asyncIterator(MESSAGE_IN_GROUP_ADDED_TOPIC),
(payload, args) => {
console.log(JSON.stringify(payload, null, 2));
return Boolean(
true /*args.userId === payload.defaultGroupAdded.userId*/,
);
},
),
},
},
Mutation: {
async addFriend(_, { userId, friendId }, ctx) {
const user = await UserModel.findOne({
where: { id: userId },
});
text: comment.text,
createdAt: Date()
};
blog.comments.push(newComment);
pubsub.publish('commentAdded', {
commentAdded: newComment,
blogId: comment.blogId
});
return newComment;
}
},
Subscription: {
commentAdded: {
subscribe: withFilter(
() => pubsub.asyncIterator('commentAdded'),
(payload, variables) => {
// The `commentAdded` blog includes events for all blogs, so we filter to only
// pass through events for the blogs specified in the query
return payload.blogId === variables.blogId;
}
)
}
}
};
interface MessageReceived {
chat: Chat
notificationMessage: string
fromUser: string
}
interface MessageReceivedArgs {
yourUser: string
}
export default {
Subscription: {
messageReceived: {
resolve: (obj: MessageReceived) => obj,
subscribe: withFilter(
(root, args, { pubsub }: GraphQLContext) => pubsub.asyncIterator(SUBSCRIPTION_TRIGGERS.MESSAGE_RECEIVED),
(obj: MessageReceived, args: MessageReceivedArgs) => {
// @ts-ignore
return obj.fromUser.toString() !== args.yourUser && obj.chat.users.includes(args.yourUser)
},
),
},
},
Chat: {
...chatResolvers.Chat
},
Query: {
...userResolvers.Query,
...chatResolvers.Query,
},
Mutation: {
return updatedUser;
}
throw new Error(
'Something went wrong while uploading image to Cloudinary.'
);
},
};
const Subscription = {
/**
* Subscribes to user's isOnline change event
*/
isUserOnline: {
subscribe: withFilter(
() => pubSub.asyncIterator(IS_USER_ONLINE),
(payload, variables, { authUser }) => variables.authUserId === authUser.id
),
},
};
export default { Query, Mutation, Subscription };
raw: true,
});
pubsub.publish(USER_UPDATED, { user });
return user;
} catch (err) {
throw new Error(err);
}
},
},
Subscription: {
userAdded: {
subscribe: (_, args, { pubsub }) => pubsub.asyncIterator(USER_ADDED),
},
userUpdated: {
subscribe: withFilter(
(_, args, { pubsub }) => pubsub.asyncIterator(USER_UPDATED),
(payload, variables) => {
return payload.userUpdated.id === variables.id;
},
),
},
},
User: {
notifications: (_, args, { models }, info) => {
return models.Notification.findAll({
where: {
userId: _.id,
},
});
},
reviews: (_, args, { models }, info) => {
{ multi: true }
);
return true;
} catch (e) {
return false;
}
},
};
const Subscription = {
/**
* Subscribes to notification created or deleted event
*/
notificationCreatedOrDeleted: {
subscribe: withFilter(
() => pubSub.asyncIterator(NOTIFICATION_CREATED_OR_DELETED),
(payload, variables, { authUser }) => {
const userId = payload.notificationCreatedOrDeleted.notification.user.toString();
return authUser && authUser.id === userId;
}
),
},
};
export default { Query, Mutation, Subscription };
function getNewMessages() {
return withFilter(
() => pubSub.asyncIterator(GET_CHAT_SUB),
(payload, variable) => payload.chatId === variable.chatId
);
}
const isAuthUserSenderOrReceiver =
authUserId === sender.id || authUserId === receiver.id;
const isUserSenderOrReceiver =
userId === sender.id || userId === receiver.id;
return isAuthUserSenderOrReceiver && isUserSenderOrReceiver;
}
),
},
/**
* Subscribes to new conversations event
*/
newConversation: {
subscribe: withFilter(
() => pubSub.asyncIterator(NEW_CONVERSATION),
(payload, variables, { authUser }) =>
authUser && authUser.id === payload.newConversation.receiverId
),
},
};
export default { Mutation, Query, Subscription };
targetType = capitalizeType(targetType);
const extension = gql`
type ${subscriptionType} {
updateType: ${enumType}
payload: ${targetType}
}
${subType} {
${subscriptionField}(name: String, namespace: String!): ${subscriptionType}
}
`;
const resolvers = {
Subscription: {
[subscriptionField]: {
subscribe: withFilter(
() => pubsubAsyncIterator(label),
(payload, variables, info, context) => {
const resourceApi = subscriptions.filter(sub => {
return `${sub.type}Update` === context.fieldName;
})[0];
return (
payload.apiObj.metadata.namespace === variables.namespace &&
(variables.name === undefined ||
payload.apiObj.metadata.name === variables.name) &&
checkPermission(
info.token,
resourceApi.group,
resourceApi.resource,
variables.namespace,
variables.name,
kubeApiUrl