apollo-server-express#PubSub TypeScript Examples
The following examples show how to use
apollo-server-express#PubSub.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: pubsub.ts From OpenVolunteerPlatform with MIT License | 6 votes |
export function getPubSub() {
const mqttHost = process.env.MQTT_HOST
if (mqttHost) {
console.log('Using MQTT PubSub')
const mqttOptions = {
host: mqttHost,
servername: mqttHost, // needed to work in OpenShift. Lookup SNI.
username: process.env.MQTT_USERNAME || '',
password: process.env.MQTT_PASSWORD || '',
port: process.env.MQTT_PORT || '1883',
protocol: process.env.MQTT_PROTOCOL || 'mqtt',
rejectUnauthorized: false
}
// Types are broken
const client = mqtt.connect(mqttHost, mqttOptions as any)
console.log(`attempting to connect to messaging service ${mqttHost}`)
client.on('connect', () => {
console.log('connected to messaging service')
})
client.on('error', (error) => {
console.log('error with mqtt connection')
console.log(error)
})
return new MQTTPubSub({ client })
}
console.log('Using In Memory PubSub')
return new PubSub()
}
Example #2
Source File: gcall.ts From convoychat with GNU General Public License v3.0 | 6 votes |
createFakeContext = (currentUser?: any) => {
let user = {
...fakeUser,
};
if (currentUser) {
user = {
...currentUser,
id: currentUser._id,
};
}
return {
currentUser: {
...user,
},
getUser: () => user,
logout: () => {},
logOut: () => {},
isAuthenticated: () => true,
isUnauthenticated: () => false,
authenticate: () => user,
login: () => true,
req: {
user: user,
},
res: {} as any,
pubsub: new PubSub(),
};
}
Example #3
Source File: server.ts From Full-Stack-React-TypeScript-and-Node with MIT License | 5 votes |
pubsub = new PubSub()
Example #4
Source File: server.ts From Full-Stack-React-TypeScript-and-Node with MIT License | 5 votes |
pubsub = new PubSub()
Example #5
Source File: index.ts From convoychat with GNU General Public License v3.0 | 5 votes |
pubsub = new PubSub()
Example #6
Source File: index.ts From ExpressLRS-Configurator with GNU General Public License v3.0 | 4 votes |
async start(
config: IConfig,
logger: LoggerService,
port: number
): Promise<http.Server> {
const pubSub = new PubSub();
Container.set([{ id: ConfigToken, value: config }]);
Container.set([{ id: PubSubToken, value: pubSub }]);
Container.set([{ id: LoggerToken, value: logger }]);
const platformio = new Platformio(
config.getPlatformioPath,
config.platformioStateTempStoragePath,
config.PATH,
config.env,
logger
);
Container.set(
FirmwareService,
new FirmwareService(
config.PATH,
config.firmwaresPath,
platformio,
new FirmwareBuilder(platformio),
pubSub,
logger
)
);
Container.set(
UpdatesService,
new UpdatesService(
config.configuratorGit.owner,
config.configuratorGit.repositoryName
)
);
Container.set(
SerialMonitorService,
new SerialMonitorService(pubSub, logger)
);
const mDnsNotifications = new MulticastDnsNotificationsService(
pubSub,
logger
);
if (config.multicastDnsSimulatorEnabled) {
Container.set(
MulticastDnsService,
new MulticastDnsSimulatorService(mDnsNotifications)
);
} else {
Container.set(
MulticastDnsService,
new MulticastDnsService(mDnsNotifications, logger)
);
}
const deviceService = new DeviceService(logger);
await deviceService.loadFromFileSystemAt(config.devicesPath);
Container.set(DeviceService, deviceService);
if (config.userDefinesLoader === FirmwareParamsLoaderType.Git) {
Container.set(
UserDefinesBuilder,
new UserDefinesBuilder(
new GitUserDefinesLoader(
logger,
config.PATH,
config.userDefinesStoragePath
),
deviceService
)
);
} else if (config.userDefinesLoader === FirmwareParamsLoaderType.Http) {
Container.set(
UserDefinesBuilder,
new UserDefinesBuilder(new HttpUserDefinesLoader(logger), deviceService)
);
}
if (config.targetsLoader === FirmwareParamsLoaderType.Git) {
Container.set(
TargetsLoader,
new GitTargetsService(
logger,
deviceService,
config.PATH,
config.targetsStoragePath
)
);
} else if (config.targetsLoader === FirmwareParamsLoaderType.Http) {
Container.set(
TargetsLoader,
new HttpTargetsService(logger, deviceService)
);
} else {
throw new Error('FirmwareTargetsLoaderType is not set');
}
Container.set(LuaService, new LuaService(logger));
const schema = await buildSchema({
resolvers: [
FirmwareResolver,
SourcesResolver,
UpdatesResolver,
SerialMonitorResolver,
MulticastDnsMonitorResolver,
LuaResolver,
],
container: Container,
pubSub,
});
const server = new ApolloServer({
schema,
introspection: true,
});
this.app = express();
server.applyMiddleware({
app: this.app,
});
this.server = this.app.listen({ port });
/*
I know, crazy. It is 45 minutes, but on slower network connection it might take a while to download
and install all Platformio dependencies and build firmware.
*/
this.server.setTimeout(45 * 60 * 1000);
server.installSubscriptionHandlers(this.server);
return this.server;
}