naystack - v1.5.10
    Preparing search index...

    Function FieldLibrary

    • Builds a type-graphql @Resolver(() => type) class that resolves computed fields on a parent GraphQL type. Each key in the queries object becomes a @FieldResolver on that type.

      Pass the returned class in the resolvers array of initGraphQLServer.

      Parameters

      • type: ClassType

        The parent GraphQL type class (e.g. User). Must be a @ObjectType class.

      • queries: T

        Object mapping field names to FieldResolverDefinitions (from field()).

      Returns typeof GeneratedResolver

      A @Resolver class for the given type; pass it in initGraphQLServer's resolvers array.

      import { FieldLibrary, field } from "naystack/graphql";
      import { User } from "./types";
      import type { UserDB } from "./db";
      import organizations from "./resolvers/organizations-field";

      export const UserFieldResolvers = FieldLibrary<UserDB>(User, {
      organizations, // Resolves User.organizations from the UserDB row
      });
      export const OrgFieldResolvers = FieldLibrary<OrgDB>(OrgGQL, {
      access: field(
      async (root, ctx) => checkOrgAccess(ctx.userId, root.id),
      { output: AccessRole, outputOptions: { nullable: true } },
      ),
      });