type-graphql#createResolversMap TypeScript Examples

The following examples show how to use type-graphql#createResolversMap. 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: build-federated-schema.ts    From opensaas with MIT License 6 votes vote down vote up
export async function buildFederatedSchema(
  options: Omit<BuildSchemaOptions, 'skipCheck'>,
  referenceResolvers?: GraphQLResolverMap<any>,
) {
  const schema = await buildSchema({
    ...options,
    directives: [...specifiedDirectives, ...federationDirectives, ...(options.directives || [])],
    skipCheck: true,
  });

  const federatedSchema = buildApolloFederationSchema({
    typeDefs: gql(printSchema(schema)),
    resolvers: createResolversMap(schema) as any,
  });

  if (referenceResolvers) {
    addResolversToSchema(federatedSchema, referenceResolvers);
  }
  return federatedSchema;
}
Example #2
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,
    };
  }