Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const TeamsSubscriptions = {
teamsUpdate: {
resolve(rootValue, { simulatorId, type, cleared }) {
// Get the simulator
let returnVal = rootValue;
if (type) {
returnVal = returnVal.filter(t => t.type === type);
}
if (simulatorId) {
returnVal = returnVal.filter(t => t.simulatorId === simulatorId);
}
if (cleared) return returnVal;
return returnVal.filter(c => !c.cleared);
},
subscribe: withFilter(
() => pubsub.asyncIterator("teamsUpdate"),
(rootValue, { simulatorId, type }) => true
)
}
};
export const TeamsTypes = {
Team: {
location(team) {
const deck = App.decks.find(d => d.id === team.location);
if (deck) {
return deck;
}
return App.rooms.find(r => r.id === team.location);
},
officers(team) {
import { withFilter } from 'graphql-subscriptions';
import { getThread } from '../models/thread';
import { userCanViewChannel, userCanViewDirectMessageThread } from './utils';
const { listenToNewMessages } = require('../models/message');
import asyncify from '../utils/asyncify';
import { trackUserThreadLastSeenQueue } from 'shared/bull/queues.js';
import type { Message } from '../models/message';
/**
* Define the message subscription resolvers
*/
module.exports = {
Subscription: {
messageAdded: {
resolve: (message: any) => message,
subscribe: withFilter(
asyncify(listenToNewMessages, err => {
throw new Error(err);
}),
async (message, { thread }, { user }) => {
// Message was sent in different thread, early return
if (message.threadId !== thread) return false;
if (message.threadType === 'directMessageThread') {
if (!user) return false;
return userCanViewDirectMessageThread(message.threadId, user.id);
}
const threadData = await getThread(message.threadId);
if (!threadData) return false;
return await userCanViewChannel(
threadData.channelId,
}
})
export default {
// auth stuffs
newComment: {
type: CommentType,
args: {
input: {
type: NewCommentSubscriptionInput
}
},
// resolve have to be there... dont know why yet
resolve: data => data,
subscribe: withFilter(
() => pubsub.asyncIterator(SubsTypes.NewComment), (payload, variables = {}, context) => {
// TODO: can't add context in playground and test subscription without frontend
// disable auth for dev env?
if (isNilOrEmpty(context.user)) {
return false
}
const globalReportId = variables.input &&Â variables.input.reportId
const reportId = Number(fromGlobalId(globalReportId).id)
return payload.report_id === reportId
}
),
}
}
links: () => db.links
},
Mutation: {
createLink: (_, { url, description }) => {
const link = { id: shortid.generate(), description, url };
db.links.push(link);
pubsub.publish(CHANNEL.LINK, { [SUBSCRIPTION.LINK]: link });
return link;
}
},
Subscription: {
[SUBSCRIPTION.LINK]: {
resolve: (payload, args, context, info) => {
return payload.link;
},
subscribe: withFilter(
(rootValue, args, context, info) => {
return pubsub.asyncIterator(CHANNEL.LINK);
},
(payload, variables, context, info) => {
console.log('payload: ', payload);
console.log('variables: ', variables);
return true;
}
)
}
}
};
const schema = makeExecutableSchema({
typeDefs,
resolvers
(rootValue, { simulatorId }) => {
if (simulatorId)
return !!rootValue.find(s => s.simulatorId === simulatorId);
return true;
}
)
},
coolantSystemUpdate: {
resolve(rootValue, { simulatorId, systemId }) {
let returnRes = rootValue;
if (simulatorId)
returnRes = returnRes.filter(s => s.simulatorId === simulatorId);
if (systemId) returnRes = returnRes.filter(s => s.id === systemId);
return returnRes;
},
subscribe: withFilter(
() => pubsub.asyncIterator("coolantSystemUpdate"),
(rootValue, { simulatorId, systemId }) => {
let returnRes = rootValue;
if (simulatorId)
returnRes = returnRes.filter(s => s.simulatorId === simulatorId);
if (systemId) returnRes = returnRes.filter(s => s.id === systemId);
return returnRes.length > 0 ? true : false;
}
)
}
};
},
showViewscreenTactical(rootValue, args, context) {
App.handleEvent(args, "showViewscreenTactical", context);
}
};
export const TacticalMapSubscriptions = {
tacticalMapsUpdate: {
resolve(rootValue, { flightId }) {
let returnRes = rootValue;
if (flightId) {
returnRes = returnRes.filter(s => s.flightId === flightId);
}
return returnRes;
},
subscribe: withFilter(
() => pubsub.asyncIterator("tacticalMapsUpdate"),
(rootValue, { flightId }) => {
if (flightId) {
return rootValue.filter(s => s.flightId === flightId).length > 0;
}
return !!(rootValue && rootValue.length);
}
)
},
tacticalMapUpdate: {
resolve(rootValue, { id }) {
return rootValue;
},
subscribe: withFilter(
() => pubsub.asyncIterator("tacticalMapUpdate"),
(rootValue, { id }) => {
App.handleEvent({ layout }, "updateCoreLayout", context);
},
addCoreLayout(_, { layout }, context) {
App.handleEvent({ layout }, "addCoreLayout", context);
},
removeCoreLayout(_, { id }, context) {
App.handleEvent({ id }, "removeCoreLayout", context);
}
};
export const CoreLayoutSubscriptions = {
coreLayoutChange: {
resolve(rootValue) {
return rootValue;
},
subscribe: withFilter(
() => pubsub.asyncIterator("coreLayoutChange"),
rootValue => {
return !!(rootValue && rootValue.length);
}
)
}
};
App.handleEvent(args, "activateThx", context);
},
deactivateThx(root, args, context) {
App.handleEvent(args, "deactivateThx", context);
},
resetThx(root, args, context) {
App.handleEvent(args, "resetThx", context);
}
};
export const ThxSubscriptions = {
thxUpdate: {
resolve(rootValue, { simulatorId }) {
return rootValue.filter(s => s.simulatorId === simulatorId);
},
subscribe: withFilter(
() => pubsub.asyncIterator("thxUpdate"),
(rootValue, { simulatorId }) => {
if (simulatorId) {
return !!rootValue.find(s => s.simulatorId === simulatorId);
}
return true;
}
)
}
};
setTransporterTargets(_, { transporter, targets }, context) {
App.handleEvent({ transporter, targets }, "setTransporterTargets", context);
return "";
},
setTransporterChargeSpeed(root, args, context) {
App.handleEvent(args, "setTransporterChargeSpeed", context);
}
};
export const TransporterSubscriptions = {
transporterUpdate: {
resolve(rootValue, { simulatorId }) {
if (rootValue.simulatorId !== simulatorId) return false;
return rootValue;
},
subscribe: withFilter(
() => pubsub.asyncIterator("transporterUpdate"),
rootValue => !!rootValue
)
}
};
App.handleEvent(args, "updateSoftwarePanel", context);
},
removeSoftwarePanel(rootValue, args, context) {
App.handleEvent(args, "removeSoftwarePanel", context);
}
};
export const SoftwarePanelsSubscriptions = {
softwarePanelsUpdate: {
resolve(rootValue, { simulatorId }) {
if (simulatorId) {
return rootValue.filter(s => s.simulatorId === simulatorId);
}
return rootValue.filter(s => !s.simulatorId);
},
subscribe: withFilter(
() => pubsub.asyncIterator("softwarePanelsUpdate"),
rootValue => !!(rootValue && rootValue.length)
)
}
};