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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gftdcojp/orpc-graphql-gateway

v0.1.0

Published

oRPC routerからGraphQL schemaを自動生成するライブラリ

Readme

@gftdcojp/orpc-graphql-gateway

Automatically generate GraphQL schemas from oRPC routers. Use GraphQL with the same ease as orpcOpenapi.

Overview

"Write once in your router, get oRPC, OpenAPI, and GraphQL from the same type information."

@gftdcojp/orpc-graphql-gateway treats your oRPC router as the single source of truth and automatically generates GraphQL schemas. This allows you to leverage GraphQL's versatility while maintaining type safety.

Features

  • 🎯 Single Source of Truth: Centralize all procedures in your oRPC router
  • 🔄 Automatic Conversion: Automatic conversion from Zod schemas to GraphQL types
  • 🚀 Type Safe: Leverages TypeScript's type system
  • 🔌 Easy Integration: Simple integration with frameworks like Next.js
  • 📦 Same Mental Model: Use GraphQL with the same ease as orpcOpenapi

Installation

pnpm add @gftdcojp/orpc-graphql-gateway graphql graphql-yoga

Getting Started

1. Define your oRPC router

// src/server/orpc.ts
import { z } from "zod";
import { orpc } from "@orpc/server";

export const router = orpc.router({
  user: orpc.procedure
    .input(z.object({ id: z.string() }))
    .output(z.object({ id: z.string(), name: z.string() }))
    .handler(async ({ input }) => {
      return { id: input.id, name: "Jun" };
    }),
});

2. Generate GraphQL Gateway

// src/server/graphql.ts
import { router } from "./orpc";
import { orpcGraphQL } from "@gftdcojp/orpc-graphql-gateway";

export const gql = orpcGraphQL(router);

export const { schema, sdl, createHandler } = gql;

3. Integrate with Next.js

// src/app/api/graphql/route.ts
import { createHandler } from "@/server/graphql";

export { createHandler as GET, createHandler as POST };

That's it! Your GraphQL endpoint is now available at /api/graphql.

API Reference

orpcGraphQL(router, options?)

Generates a GraphQL Gateway from an oRPC router.

Parameters:

  • router: oRPC router object
  • options: Optional configuration
    • namingPolicy: Naming resolution policy ("flat" | "nested")
    • isQueryFn: Custom function to determine if a procedure is a query
    • federation: Federation configuration
      • enabled: Enable Federation
      • keyBy: Entity key configuration

Returns: OrpcGraphQLResult

interface OrpcGraphQLResult {
  /** GraphQL schema object */
  schema: GraphQLSchema;
  /** GraphQL SDL (string) */
  sdl: string;
  /** Federated SDL (only when federation is enabled) */
  subgraphSDL?: string;
  /** Function to create HTTP handler */
  createHandler: () => RequestHandler;
}

Federation Support

Enable Federation with optional configuration:

const gql = orpcGraphQL(router, {
  federation: {
    enabled: true,
    keyBy: {
      User: "id",
    },
  },
});

// Use with Apollo Gateway
export const subgraphSDL = gql.subgraphSDL;

Zod → GraphQL Conversion Rules

| Zod | GraphQL | | ----------------- | -------------------------- | | z.string() | GraphQLString | | z.number() | GraphQLFloat or Int | | z.boolean() | GraphQLBoolean | | z.array(x) | GraphQLList | | z.object({...}) | GraphQLInputObjectType | | z.enum([...]) | GraphQLEnumType | | z.nullable(x) | nullable | | z.union(...) | GraphQLUnionType (output) |

Naming Policy

Nested routers are converted to flat names:

  • user.getuser_get
  • post.createpost_create

Lower-Level API

For advanced use cases, you can use lower-level APIs:

import { buildGraphQLSchemaFromOrpc } from "@gftdcojp/orpc-graphql-gateway";

const schema = buildGraphQLSchemaFromOrpc(router);

Documentation

For more information, see the oRPC OpenAPI Getting Started Guide.

License

MIT