npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tinkerstack/graphql-annotation

v0.0.3

Published

Better type-safe-able graphql directives

Downloads

359

Readme


Who is this intended for?

This library is designed to solve a specific scenario in mind:

  1. There's a primary Gateway and separately developed SubGateways, both of each uses graphql.
  2. Front-end or external non-backend consumers interact with SubGateway resolvers stitched through Gateway
  3. Resolvers at SubGateway requires additional resource/guard/processing from Gateway.
  4. SubGateway team does not have access to Gateway nor can they run a local instance.
  5. SubGateway team does not require Gateway features during development, only during deployment.

Available solutions often utilize Remote-Produce-Calls (RPCs) libraries to let SubGateway invoke Gateway methods through HTTP transport, which unfortunately fails point 4 and 5, of which this library answers through annotations.

However, if SubGateway needs to make additional calls to Gateway for mutation or other purposes, then this library should only be considered as a mean of optimization and you are better off just running an RPC library at the small of performance and back-and-forth.

TL;DR: Only use this library if you HAVE TO achieve complete isolation between Gateway and SubGateway development cycle.

Usage

You can find examples in src/examples for more details. Note that graphql-annotation should be replaced with workspace name in internal projects.

// gateway

import {
  GraphQLAnnotationModule, 
  GraphQLAnnotationSchemaLoader
} from "graphql-annotation";

@Module({
  imports: [
    GraphQLAnnotationModule.forRoot(),
    GraphQLModule.forRootAsync<ApolloDriverConfig>({
      driver: ApolloDriver,
      useFactory: (loader: GraphQLAnnotatedSchemaLoader) => ({
        async transformSchema(schema) {
          return stitchSchemas({
            subschemas: [
              { schema },
              {
                // Load external annotated schemas
                schema: await loader.load({
                  example: "http://localhost:3031/graphql",
                }),
              },
            ],
          });
        },
      }),
      inject: [GraphQLAnnotatedSchemaLoader],
    }),
  ],
})
export class GatewayAppModule {}


// It is recommended that you wrap the `Annotate` decorator in a function and in the gateway to ensure `gateway` team knows that's implemented. `sub-gateway` team could reference this through github submodule.

export type RoleGroups = ("user" | "admin" | "super-admin")[];
export const ProtectedResolver = (roles: RoleGroups) =>
  Annotate("protected", { data: { roles } });

export const InjectableArg = (argName: string, resourceType: string) =>
  Annotate("resource", { data: { resourceType }, parameter: argName });

@Injectable()
export class ExampleGuard implements CanActivate {
  canActivate(context: ExecutionContext) {
    // Do something with your execution context
    return true;
  }
}

@Resolver()
export class SubgatewayResolver {
  // NOTE: You can use normal nest and graphql decorators.
  // Just note that `ResolveAnnotation` must be in a `Resolver`

  @UseGuards(ExampleGuard)
  @ResolveAnnotation("protected") 
  verifyUser(context: ExecutionContext, next: () => void) {}

  // If empty would use function name as annotation tag
  @ResolveAnnotation()
  resource(
    // WARN: this is NOT validated like in graphql though
    @Args("resourceType") resourceType: string,
    @Context() context: GraphQLExecutionContext,
  ) {
    return "this-is-gateway-provided-username";
  }
}

// ---------------------------------------------

// sub-gateway
@Module({
  imports: [
    GraphQLModule.forRoot<ApolloDriverConfig>({
      /* Put your graphql config here*/
    }),
    GraphQLAnnotationModule.forRoot({
      serveAnnotations: true,
      // Name is only for identification at the time of writing, which does not support annotation filtering.
      serveConfig: { name: "<subgateway-a>" },
    }),
    ExampleProducerModule,
  ],
})
export class SubGatewayAppModule {}

@Resolver()
export class ExampleProducerResolver {
  @Query(() => [String])
  @ProtectedResolver(["admin"])
  testProtectedQuery() {
    return ["This resolver should only be available to if guard check passed"];
  }
  @Query(() => [String])
  testQueryWithParam(
    @InjectableArg("username", "session:username")
    username: string
  ) {
    return [`Received params: ${username}`];
  }
  @Query(() => [String])
  testPublicQuery() {
    return ["This resolver should be available to everyone"];
  }
}