How to use the @graphql-modules/core.injectable function in @graphql-modules/core

To help you get started, we’ve selected a few @graphql-modules/core 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 Urigo / graphql-modules / examples / messages / src / modules / users / users.provider.ts View on Github external
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);
  }
}
github Urigo / graphql-modules / examples / di / src / modules / info / providers / info.ts View on Github external
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;
  }
}
github Urigo / graphql-modules / examples / messages / src / modules / messages / messages.provider.ts View on Github external
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);
    });