You can use GraphQL Mesh Compose + Hive Gateway as a type-safe SDK in an existing TypeScript
project, or execute operations programmatically without standing up an HTTP server.
The runnable example is
Hive Gateway examples/typed-sdk
(open in CodeSandbox). It
composes a supergraph with Mesh Compose, generates getSdk with GraphQL Codegen, and calls queries
/ mutations / subscriptions through createGatewayRuntime + runtime.sdkRequester.
Supergraph as a file
Compose to SDL (what the example uses) or to a JS module if you want to import the schema:
v0 generated this inside .mesh. v1 uses the same Codegen plugin Mesh used internally
(typescript-generic-sdk),
with the supergraph as schema and your operations as documents.
This is what
examples/typed-sdk/example.ts
does: start an in-process gateway, pass runtime.sdkRequester into getSdk.
import { readFileSync } from 'node:fs'import { createGatewayRuntime } from '@graphql-hive/gateway'import { getSdk } from './sdk/generated'await using runtime = createGatewayRuntime({ supergraph: readFileSync('./supergraph.graphql', 'utf-8')})const sdk = getSdk(runtime.sdkRequester)const todos = await sdk.Todos()await sdk.AddTodo({ text: 'Write tests' })const iterable = sdk.TodoAdded()const iterator = iterable[Symbol.asyncIterator]()
Run the example locally (from its README): download example.tar.gz, npm i, npm run codegen,
start the subgraph, compose, then npm run gateway — or run example.ts for the SDK path. Full
steps:
examples/typed-sdk README.
With getSdkRequesterForUnifiedGraph
If you already import a JS supergraph and do not need createGatewayRuntime:
import { getSdkRequesterForUnifiedGraph } from '@graphql-hive/gateway'import { getSdk } from './sdk/generated'const sdkRequester = getSdkRequesterForUnifiedGraph({ getUnifiedGraph: () => import('./supergraph.js').then(m => m.default)})const sdk = getSdk(sdkRequester)const result = await sdk.myQuery({ someVar: 'SOME_VALUE' })