Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { injectable } from '@graphql-modules/core';
import * as users from '../../3rd-party/users';
import data from './data';
@injectable()
export class Users implements users.Users {
async me() {
return data.find(u => u.id === 1);
}
async users() {
return data;
}
async user(id: number) {
return data.find(u => u.id === id);
}
}
import {
injectable,
inject,
ModuleConfig,
CommunicationBridge,
AppInfo,
} from '@graphql-modules/core';
@injectable()
export class Info {
constructor(
@inject(ModuleConfig('info')) private config: any,
@inject(CommunicationBridge)
private communicationBridge: CommunicationBridge,
@inject(AppInfo) private app: AppInfo,
) {}
getVersion() {
this.communicationBridge.publish(
'ASKED_FOR_VERSION',
`${this.app.getRequest().method}: ${this.app.getRequest().url}`,
);
return this.config.version;
}
}
import { injectable, inject } from '@graphql-modules/core';
import { Users } from '../../3rd-party/users';
import data from './data';
@injectable()
export class Messages {
constructor(@inject(Users) private users: Users) {}
async chat(userId: number) {
const me = await this.users.me();
if (me.id === userId) {
throw new Error(
'You cannot talk with yourself, you weird, crazy person!',
);
}
return data.filter(msg => {
const ids = [msg.recipient, msg.sender];
return ids.includes(me.id) && ids.includes(userId);
});