@nestjs/graphql#GqlModuleOptions TypeScript Examples

The following examples show how to use @nestjs/graphql#GqlModuleOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: typegraphql-options.factory.ts    From typegraphql-nestjs with MIT License 6 votes vote down vote up
async createGqlOptions(): Promise<GqlModuleOptions> {
    const { globalMiddlewares } = this.rootModuleOptions;
    const { resolversClasses, container, orphanedTypes } =
      this.optionsPreparatorService.prepareOptions<TypeGraphQLFeatureModuleOptions>(
        TYPEGRAPHQL_FEATURE_MODULE_OPTIONS,
        globalMiddlewares,
      );

    const schema = await buildSchema({
      ...this.rootModuleOptions,
      resolvers: resolversClasses as NonEmptyArray<ClassType>,
      orphanedTypes,
      container,
    });

    return {
      ...this.rootModuleOptions,
      schema,
    };
  }
Example #2
Source File: graphql.config.ts    From nestjs-jaeger-tracing with MIT License 6 votes vote down vote up
graphqlConfig: GqlModuleOptions = {
  typePaths: ['./src/schemas/*.graphql'],
  debug: true,
  playground: true,
  introspection: true,
  installSubscriptionHandlers: true,
  subscriptions: { keepAlive: 30 * 1000 },
  context: ({ req, connection }: IContextFunction) => {
    if (connection) {
      return {
        req: {
          headers: {
            authorization:
              connection.context.authorization ||
              connection.context.Authorization,
          },
        },
      };
    }
    return { req };
  },
}
Example #3
Source File: config.service.ts    From nestjs-mercurius with MIT License 5 votes vote down vote up
createGqlOptions(): GqlModuleOptions {
    return {
      typePaths: [join(__dirname, '**', '*.graphql')],
    };
  }
Example #4
Source File: typegraphql-options-federation.factory.ts    From typegraphql-nestjs with MIT License 5 votes vote down vote up
async createGqlOptions(): Promise<GqlModuleOptions> {
    const { globalMiddlewares } = this.rootModuleOptions;
    const {
      resolversClasses,
      container,
      orphanedTypes,
      featureModuleOptionsArray,
    } = this.optionsPreparatorService.prepareOptions<TypeGraphQLFeatureFedarationModuleOptions>(
      TYPEGRAPHQL_FEATURE_FEDERATION_MODULE_OPTIONS,
      globalMiddlewares,
    );

    const referenceResolversArray = [...featureModuleOptionsArray].filter(
      it => it.referenceResolvers,
    );

    const referenceResolvers =
      referenceResolversArray.length > 0
        ? Object.fromEntries(
            referenceResolversArray.flatMap(it =>
              Object.entries(it.referenceResolvers!),
            ),
          )
        : undefined;

    const baseSchema = await buildSchema({
      ...this.rootModuleOptions,
      directives: [...specifiedDirectives, ...federationDirectives],
      resolvers: resolversClasses as NonEmptyArray<ClassType>,
      orphanedTypes,
      container,
    });

    const schema = buildFederatedSchema({
      typeDefs: gql(printSchema(baseSchema)),
      resolvers: createResolversMap(baseSchema) as GraphQLResolverMap<any>,
    });

    if (referenceResolvers) {
      addResolversToSchema(schema, referenceResolvers);
    }

    return {
      ...this.rootModuleOptions,
      schema,
    };
  }