How to use @graphql-modules/di - 10 common examples

To help you get started, we’ve selected a few @graphql-modules/di 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 Coding-Coach / coding-coach-api / src / repositories / mentor-repository / mentor-repository.ts View on Github external
import { Injectable, Inject } from '@graphql-modules/di';
import { MentorEntity } from './mentor-entity';
import { TableService, TableQuery } from 'azure-storage';

export interface IMentorRepository {
  getMentees(mentorId: string): Promise;
  addMentee(mentor: MentorEntity): Promise;
  tableName: string;
}

@Injectable()
class MentorRepository implements IMentorRepository {
  public tableName: string = 'mentorentity';

  constructor(@Inject('TableService') private tableService: TableService) {
    this.tableService.doesTableExist(this.tableName, (error, result) => {
      if (!result.exists) {
        this.tableService.createTable(this.tableName, (error, result) => {
          console.log(error);
          console.log(result);
        });
      }
    });
  }

  public async getMentees(mentorId: string): Promise {
    return new Promise((resolve, reject) => {
github Coding-Coach / coding-coach-api / src / repositories / mentor-repository / mentor-repository.ts View on Github external
  constructor(@Inject('TableService') private tableService: TableService) {
    this.tableService.doesTableExist(this.tableName, (error, result) => {
      if (!result.exists) {
        this.tableService.createTable(this.tableName, (error, result) => {
          console.log(error);
          console.log(result);
        });
      }
    });
  }
github Coding-Coach / coding-coach-api / src / repositories / mentee-repository / mentee-repository.ts View on Github external
  constructor(@Inject('TableService') private tableService: TableService) {
    this.tableService.doesTableExist(this.tableName, (error, result) => {
      if (!result.exists) {
        this.tableService.createTable(this.tableName, (error, result) => {
          console.log(error);
          console.log(result);
        });
      }
    });
  }
  addMentor(mentee: MenteeEntity): Promise {
github maapteh / graphql-modules-app / packages / server / src / modules / product / providers / product.ts View on Github external
import { Injectable, ProviderScope } from '@graphql-modules/di';
import dataloader from 'dataloader';
import nodeFetch, { Response } from 'node-fetch';
import { Products, Product } from '../../../_graphql';
import { checkStatus } from '../../../helpers';
import { CREDENTIALS, BOL_API } from '../../../constants';
import { productDataLoader } from './product-data-loader';

@Injectable({
    scope: ProviderScope.Session,
})
export class ProductProvider {
    private dataLoaderProduct: any;

    constructor() {
        this.dataLoaderProduct = new dataloader(keys =>
            productDataLoader(keys),
        );
    }

    /**
     * Example 1: not dataloader used while it should
     */
    public async getProducts(id: string): Promise {
        const url = `${BOL_API}/lists/?ids=${id}&limit=12&format=json&${CREDENTIALS}`;
        console.log(`[BAD] no dataloader: ${url.slice(0, -40)}`);
github Urigo / WhatsApp-Clone-Server / modules / message / providers / message.provider.ts View on Github external
import { Injectable } from '@graphql-modules/di'
import { PubSub } from 'apollo-server-express'
import { Connection } from 'typeorm'
import { User } from '../../../entity/User';
import { Chat } from '../../../entity/Chat';
import { ChatProvider } from '../../chat/providers/chat.provider';
import { Message } from '../../../entity/Message';
import { MessageType } from '../../../db';
import { AuthProvider } from '../../auth/providers/auth.provider';
import { UserProvider } from '../../user/providers/user.provider';

@Injectable()
export class MessageProvider {
  constructor(
    private pubsub: PubSub,
    private connection: Connection,
    private chatProvider: ChatProvider,
    private authProvider: AuthProvider,
    private userProvider: UserProvider,
  ) { }

  repository = this.connection.getRepository(Message);
  currentUser = this.authProvider.currentUser;

  createQueryBuilder() {
    return this.connection.createQueryBuilder(Message, 'message');
  }
github Urigo / WhatsApp-Clone-Server / modules / chat / providers / chat.provider.ts View on Github external
import { Injectable } from '@graphql-modules/di'
import { PubSub } from 'apollo-server-express'
import { Connection } from 'typeorm'
import { User } from '../../../entity/User';
import { Chat } from '../../../entity/Chat';
import { UserProvider } from '../../user/providers/user.provider';
import { AuthProvider } from '../../auth/providers/auth.provider';

@Injectable()
export class ChatProvider {
  constructor(
    private pubsub: PubSub,
    private connection: Connection,
    private userProvider: UserProvider,
    private authProvider: AuthProvider,
  ) {
  }

  repository = this.connection.getRepository(Chat);
  currentUser = this.authProvider.currentUser;

  createQueryBuilder() {
    return this.connection.createQueryBuilder(Chat, 'chat');
  }
github Coding-Coach / coding-coach-api / src / handlers / get-mentees / get-mentees-handler.ts View on Github external
import 'reflect-metadata';
import { Inject, Injectable } from '@graphql-modules/di';
import { Context, HttpRequest } from '@azure/functions';
import { IMentorRepository } from '@repositories/mentor-repository/mentor-repository';

@Injectable()
class GetMentees {
  constructor(
    @Inject('IMentorRepository') private mentorRepository: IMentorRepository
  ) {}
  index = async (context: Context, req: HttpRequest): Promise => {
    context.log('JavaScript HTTP trigger function processed a request.');
    const mentorId = req.query.mentorId;
    const mentees = await this.mentorRepository.getMentees(mentorId);

    context.res = {
      status: '200',
      body: JSON.stringify(mentees),
    };
  };
}
github darkbasic / graphql-modules-seed / src / modules / messages / providers / messages.provider.ts View on Github external
import { Inject, Injectable } from '@graphql-modules/di';
import { ChatDbObject, MessageDbObject } from "@models";
import { CHATS, MESSAGES } from "@modules/common";

@Injectable()
export class MessagesProvider {

  constructor(
    @Inject(MESSAGES) private messages: MessageDbObject[],
    @Inject(CHATS) private chats: ChatDbObject[],
  ) {}

  getMessages(chatId: number): MessageDbObject[] {
    return this.messages.filter(message => message.chatId === chatId);
  }

  getMessage(id: number): MessageDbObject {
    return this.messages.find(message => message.id === id);
  }

  createMessage(content: string, chatId: number): MessageDbObject {
github Urigo / graphql-modules / examples / basic-with-dependency-injection / src / modules / blog / providers / blog.ts View on Github external
authorId: 0,
    title: 'Title 1',
  },
  {
    _id: 1,
    authorId: 1,
    title: 'Title 2',
  },
  {
    _id: 2,
    authorId: 0,
    title: 'Title 3',
  },
];

@Injectable()
export class Blog {
  constructor(
    private users: Users,
  ) {}

  getPostsOf(userId: number) {
    return posts.filter(({ authorId }) => userId === authorId);
  }

  allPosts() {
    return posts;
  }

  getAuthor(postId: number) {
    const post = posts.find(({ _id }) => _id === postId);
github Urigo / WhatsApp-Clone-Server / modules / users / users.provider.ts View on Github external
import { Injectable, Inject, ProviderScope } from '@graphql-modules/di';
import sql from 'sql-template-strings';
import bcrypt from 'bcrypt';
import { Database } from '../common/database.provider';

const DEFAULT_PROFILE_PIC = 'https://raw.githubusercontent.com/Urigo/WhatsApp-Clone-Client-React/legacy/public/assets/default-profile-pic.jpg'

@Injectable({
  scope: ProviderScope.Session,
})
export class Users {
  @Inject() private db: Database;

  async findById(userId: string) {
    const db = await this.db.getClient();
    const { rows } = await db.query(
      sql`SELECT * FROM users WHERE id = ${userId}`
    );

    return rows[0] || null;
  }

  async findAllExcept(userId: string) {
    const db = await this.db.getClient();

@graphql-modules/di

MIT
Latest version published 5 years ago

Package Health Score

66 / 100
Full package analysis

Similar packages