How to use the @graphql-modules/di.ProviderScope.Application function in @graphql-modules/di

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 Urigo / graphql-modules / packages / core / src / graphql-module.ts View on Github external
get injector(): Injector {
    if (typeof this._cache.injector === 'undefined') {
      this.checkConfiguration();
      const injector = (this._cache.injector = new Injector({
        name: this.name,
        injectorScope: ProviderScope.Application,
        defaultProviderScope: this.selfDefaultProviderScope,
        hooks: [
          'onInit',
          'onRequest',
          'onResponse',
          'onError',
          'onConnect',
          'onOperation',
          'onOperationComplete',
          'onDisconnect'
        ],
        initialProviders: this.selfProviders,
        children: this.selfImports.map(module => module.injector)
      }));
      injector.onInstanceCreated = ({ instance }) => {
        if (
github Urigo / WhatsApp-Clone-Server / modules / chats / unsplash.api.ts View on Github external
import { Injectable, ProviderScope } from '@graphql-modules/di';
import { resolve } from 'path';
import axios from 'axios';
import { trackProvider } from '@safe-api/middleware';
import { RandomPhoto } from '../../types/unsplash';

interface RandomPhotoInput {
  query: string;
  orientation: 'landscape' | 'portrait' | 'squarish';
}

@Injectable({
  scope: ProviderScope.Application,
})
export class UnsplashApi {
  baseURL = 'https://api.unsplash.com/';

  async getRandomPhoto() {
    const trackedRandomPhoto = await trackProvider(
      async ({ query, orientation }: RandomPhotoInput) => {
        const response = await axios.get('photos/random', {
          baseURL: this.baseURL,
          headers: {
            Authorization:
              'Client-ID 4d048cfb4383b407eff92e4a2a5ec36c0a866be85e64caafa588c110efad350d',
          },
          params: {
            query,
            orientation,
github Urigo / WhatsApp-Clone-Server / modules / common / index.ts View on Github external
providers: () => [
    {
      provide: Pool,
      useValue: pool,
    },
    {
      provide: PubSub,
      scope: ProviderScope.Application,
      useValue: pubsub,
    },
    Database,
  ],
  async context({ res }) {
github Urigo / graphql-modules / packages / core / src / graphql-module.ts View on Github external
get selfDefaultProviderScope(): ProviderScope {
    let defaultProviderScope = ProviderScope.Application;
    const defaultProviderScopeDefinition = this._options.defaultProviderScope;
    if (defaultProviderScopeDefinition) {
      if (typeof defaultProviderScopeDefinition === 'function') {
        defaultProviderScope = defaultProviderScopeDefinition(this);
      } else {
        defaultProviderScope = defaultProviderScopeDefinition;
      }
    }
    return defaultProviderScope;
  }

@graphql-modules/di

MIT
Latest version published 5 years ago

Package Health Score

66 / 100
Full package analysis

Similar packages