-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgraphql-config.service.ts
More file actions
44 lines (39 loc) · 1.46 KB
/
graphql-config.service.ts
File metadata and controls
44 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { ApolloDriverConfig } from '@nestjs/apollo';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { GqlOptionsFactory } from '@nestjs/graphql';
import {
ApolloServerPluginLandingPageLocalDefault,
ApolloServerPluginLandingPageProductionDefault,
} from '@apollo/server/plugin/landingPage/default';
import GraphQLJSON from 'graphql-type-json';
import { join } from 'path';
import { cwd } from 'process';
import { httpStatusPlugin } from '../exceptions/exception.plugin';
import { EnvironmentVariables } from '../helper/env.validation';
@Injectable()
export class GraphqlConfigService implements GqlOptionsFactory<ApolloDriverConfig> {
constructor(
private readonly configService: ConfigService<EnvironmentVariables>,
) {}
createGqlOptions(): Promise<ApolloDriverConfig> | ApolloDriverConfig {
return {
resolvers: { JSON: GraphQLJSON },
autoSchemaFile: join(
cwd(),
`${this.configService.get('NODE_ENV') === 'test' ? 'test' : 'src'}/graphql-schema.gql`,
),
sortSchema: true,
playground: false,
plugins: [
httpStatusPlugin,
this.configService.get('NODE_ENV') === 'production'
? ApolloServerPluginLandingPageProductionDefault()
: ApolloServerPluginLandingPageLocalDefault(),
],
context: ({ req }) => ({ req }),
cache: 'bounded',
csrfPrevention: this.configService.get('NODE_ENV') !== 'development',
};
}
}