HBForge/Examples
22 · Integrations

GraphQL — forge/server has it built in

Pylon is Hono's GraphQL adapter. forge/server ships GraphQLEngine directly: schema + resolvers + DataLoader, no separate package.

forge/serverNodeBunDenoCF Workers
Code
pylon.js
const { WebApp, GraphQLEngine } =
  require(class="tk-str">'@hyperbridge/forge/server');

const app = new WebApp();

const gql = new GraphQLEngine({
  typeDefs: class="tk-str">`
    type Query {
      hello: String
      user(id: Int!): User
    }
    type User { id: Int, name: String }
  `,
  resolvers: {
    Query: {
      hello: () => class="tk-str">'world',
      user:  (_, { id }) => ({ id, name: class="tk-str">`User ${id}` }),
    },
  },
});

app.post(class="tk-str">'/graphql', async (c) => {
  const { query, variables } = await c.req.json();
  return c.json(await gql.execute(query, variables));
});

app.listen(3000);
How it works

GraphQLEngine is a minimal but complete GraphQL implementation: schema parsing, type resolution, validation, execution, batching.

DataLoader (also exported from forge/server) handles the N+1 query problem the same way Facebook's original library does.

Subscriptions ride on the WebSocket support already in forge/server — no additional package.

Try it
Quickstart
curl -X POST http://localhost:3000/graphql -d '{"query":"{ hello }"}'
Related modules