How to use the apollo-server-express.withFilter function in apollo-server-express

To help you get started, we’ve selected a few apollo-server-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Thorium-Sim / thorium / server / src / typeDefs / mission.js View on Github external
},
    auxTimelines(root, { simulatorId }) {
      const sim = App.simulators.find(s => s.id === simulatorId);
      return sim && sim.timelines;
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    missionsUpdate: {
      resolve: (rootValue, { missionId }) => {
        if (missionId) {
          return rootValue.filter(m => m.id === missionId);
        }
        return rootValue;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("missionsUpdate"),
        (rootValue, { missionId }) => {
          if (missionId) {
            return !!rootValue.find(m => m.id === missionId);
          }
          return true;
        }
      )
    },
    auxTimelinesUpdate: {
      resolve: (rootValue, { missionId }) => {
        return rootValue.timelines;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("auxTimelinesUpdate"),
        (rootValue, { simulatorId }) => {
github Thorium-Sim / thorium / server / src / typeDefs / crm.js View on Github external
);
      if (!crm) return null;
      let fighter = crm.fighters.find(c => c.clientId === clientId);
      if (!fighter) {
        fighter = crm.addFighter({ clientId });
      }
      return fighter;
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    crmUpdate: {
      resolve(rootQuery) {
        return rootQuery;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("crmUpdate"),
        (rootValue, { simulatorId }) => {
          return rootValue.simulatorId === simulatorId;
        }
      )
    },
    crmFighterUpdate: {
      resolve(rootQuery) {
        return rootQuery;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("crmFighterUpdate"),
        (rootValue, { simulatorId, clientId }) => {
          return (
            rootValue.simulatorId === simulatorId &&
            rootValue.clientId === clientId
github Thorium-Sim / thorium / server / src / typeDefs / computerCore.js View on Github external
},
    oneComputerCore(root, { id }) {
      return App.systems.find(s => s.id === id);
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    computerCoreUpdate: {
      resolve(rootValue, { simulatorId }) {
        let returnVal = rootValue;
        if (simulatorId) {
          returnVal = returnVal.filter(s => s.simulatorId === simulatorId);
        }
        return returnVal;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("computerCoreUpdate"),
        (rootValue, { simulatorId }) => {
          let returnVal = rootValue;
          if (simulatorId) {
            returnVal = returnVal.filter(s => s.simulatorId === simulatorId);
          }
          return returnVal.length > 0;
        }
      )
    }
  }
};

export default { schema, resolver };
github Thorium-Sim / thorium / server / src / typeDefs / softwarePanels.js View on Github external
if (simulatorId) {
        return App.softwarePanels.filter(s => s.simulatorId === simulatorId);
      }
      return App.softwarePanels.filter(s => !s.simulatorId);
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    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 => true
      )
    }
  }
};

export default { schema, resolver };
github Thorium-Sim / thorium / server / src / typeDefs / thrusters.js View on Github external
});
    },
    thruster(root, { id }) {
      return App.systems.find(s => s.id === id);
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    rotationChange: {
      resolve(root, { simulatorId }) {
        if (simulatorId) {
          return root.simulatorId === simulatorId && root;
        }
        return root;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("rotationChange"),
        rootValue => !!rootValue
      )
    }
  }
};

export default { schema, resolver };
github Thorium-Sim / thorium / server / src / typeDefs / coreFeed.js View on Github external
},
      subscribe: withFilter(
        () => pubsub.asyncIterator("coreFeedUpdate"),
        (rootValue, { simulatorId }) => {
          if (simulatorId) {
            return !!rootValue.find(r => r.simulatorId === simulatorId);
          }
          return true;
        }
      )
    },
    syncTime: {
      resolve(rootValue) {
        return rootValue;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("syncTime"),
        (rootValue, { simulatorId }) => {
          if (rootValue.simulatorId === simulatorId) {
            return true;
          }
          return false;
        }
      )
    }
  }
};

export default { schema, resolver };
github Thorium-Sim / thorium / server / src / typeDefs / clients.js View on Github external
)
    },
    cancelSound: {
      resolve: payload => payload.id,
      subscribe: withFilter(
        () => pubsub.asyncIterator("cancelSound"),
        (rootValue, { clientId }) => {
          if (rootValue && rootValue.clients.indexOf(clientId) > -1)
            return true;
          return false;
        }
      )
    },
    cancelAllSounds: {
      resolve: payload => !!payload,
      subscribe: withFilter(
        () => pubsub.asyncIterator("cancelAllSounds"),
        (rootValue, { clientId }) => {
          return rootValue && !!rootValue.find(c => c.id === clientId);
        }
      )
    },
    cancelLoopingSounds: {
      resolve: payload => !!payload,
      subscribe: withFilter(
        () => pubsub.asyncIterator("cancelLoopingSounds"),
        (rootValue, { clientId }) => {
          return rootValue && !!rootValue.find(c => c.id === clientId);
        }
      )
    }
  }
github Thorium-Sim / thorium / server / src / typeDefs / lrcomm.js View on Github external
longRangeCommunications(root, { simulatorId }) {
      let lrComm = App.systems.filter(s => s.type === "LongRangeComm");
      if (simulatorId) return lrComm.filter(s => s.simulatorId === simulatorId);
      return lrComm;
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    longRangeCommunicationsUpdate: {
      resolve(rootValue, { simulatorId }) {
        if (simulatorId) {
          return rootValue.filter(s => s.simulatorId === simulatorId);
        }
        return rootValue;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("longRangeCommunicationsUpdate"),
        rootValue => !!(rootValue && rootValue.length)
      )
    }
  }
};

export default { schema, resolver };
github Thorium-Sim / thorium / server / src / typeDefs / googleSheets.js View on Github external
const auth = getOAuthClient();
      const sheets = google.sheets({ version: "v4", auth });
      const sheet = await sheets.spreadsheets.get({ spreadsheetId });
      return sheet;
    }
  },
  Mutation: mutationHelper(schema),
  Subscription: {
    googleSheetsUpdate: {
      resolve(rootValue, { simulatorId }) {
        if (simulatorId) {
          return rootValue.filter(s => s.simulatorId === simulatorId);
        }
        return rootValue;
      },
      subscribe: withFilter(
        () => pubsub.asyncIterator("googleSheetsUpdate"),
        (rootValue, args) => {
          return true;
        }
      )
    }
  }
};

export default { schema, resolver };
github Urigo / WhatsApp-Clone-Server / modules / chat / resolvers / resolvers.ts View on Github external
groupName: groupName || '',
        groupPicture: groupPicture || '',
      }),
    updateGroup: (obj, { chatId, groupName, groupPicture }, { injector }) => injector.get(ChatProvider).updateGroup(chatId, {
      groupName: groupName || '',
      groupPicture: groupPicture || '',
    }),
    removeChat: (obj, { chatId }, { injector }) => injector.get(ChatProvider).removeChat(chatId),
    updateUser: (obj, { name, picture }, { injector }) => injector.get(ChatProvider).updateUser({
      name: name || '',
      picture: picture || '',
    }),
  },
  Subscription: {
    chatAdded: {
      subscribe: withFilter((root, args, { injector }: ModuleContext) => injector.get(PubSub).asyncIterator('chatAdded'),
        (data: { chatAdded: Chat, creatorId: number }, variables, { injector }: ModuleContext) =>
          data && injector.get(ChatProvider).filterChatAddedOrUpdated(data.chatAdded, data.creatorId)
      ),
    },
    chatUpdated: {
      subscribe: withFilter((root, args, { injector }: ModuleContext) => injector.get(PubSub).asyncIterator('chatUpdated'),
        (data: { chatUpdated: Chat, updaterId: number }, variables, { injector }: ModuleContext) =>
          data && injector.get(ChatProvider).filterChatAddedOrUpdated(data.chatUpdated, data.updaterId)
      ),
    },
  },
  Chat: {
    name: (chat, args, { injector }) => injector.get(ChatProvider).getChatName(chat),
    picture: (chat, args, { injector }) => injector.get(ChatProvider).getChatPicture(chat),
    allTimeMembers: (chat, args, { injector }) => injector.get(ChatProvider).getChatAllTimeMembers(chat),
    listingMembers: (chat, args, { injector }) => injector.get(ChatProvider).getChatListingMembers(chat),