Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 (
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,
providers: () => [
{
provide: Pool,
useValue: pool,
},
{
provide: PubSub,
scope: ProviderScope.Application,
useValue: pubsub,
},
Database,
],
async context({ res }) {
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;
}