mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 09:08:34 +00:00
Recommend @graphql-hive/gateway-runtime for programmatic usage (#5997)
This commit is contained in:
parent
dda3a0ff57
commit
3ef2a9b9d3
18 changed files with 43 additions and 34 deletions
|
|
@ -29,7 +29,7 @@ this case, we will show here how to pass the request information from your envir
|
|||
then get the response for your environment back.
|
||||
|
||||
```ts
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import type {
|
||||
ImaginaryEnvironmentRequest,
|
||||
ImaginaryEnvironmentServerContext
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ easily integrate Hive Gateway into your Express application with a few lines of
|
|||
|
||||
```ts
|
||||
import express from 'express'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const app = express()
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ Gateway endpoint.
|
|||
```ts
|
||||
import express from 'express'
|
||||
import helmet from 'helmet'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const app = express()
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ So you can benefit from the powerful plugins of Fastify ecosystem with Hive Gate
|
|||
|
||||
```ts
|
||||
import fastify, { FastifyReply, FastifyRequest } from 'fastify'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
// This is the fastify instance you have created
|
||||
const app = fastify({ logger: true })
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ of code.
|
|||
```ts
|
||||
import http from 'node:http'
|
||||
import { Readable } from 'node:stream'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import Hapi from '@hapi/hapi'
|
||||
import { schema } from './my-graphql-schema'
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import { Callout } from '@theguild/components'
|
|||
|
||||
We highly recommend to use Hive Gateway with the CLI in Node.js as described in
|
||||
[Node.js guide](/docs/gateway/deployment/runtimes/nodejs). But if you want to use Hive Gateway with
|
||||
a Node.js framework, you can use the `createGatewayRuntime` function from `@graphql-hive/gateway`
|
||||
package.
|
||||
a Node.js framework, you can use the `createGatewayRuntime` function from
|
||||
`@graphql-hive/gateway-runtime` package.
|
||||
|
||||
In this case, you have to pass your serve configuration inside `createGatewayRuntime` instead of
|
||||
exporting it `gatewayConfig` from `gateway.config.ts` file.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ code.
|
|||
|
||||
```ts
|
||||
import Koa from 'koa'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const app = new Koa()
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Hive Gateway can be integrated with Next.js easily as
|
|||
```ts
|
||||
// Next.js Custom Route Handler: https://nextjs.org/docs/app/building-your-application/routing/router-handlers
|
||||
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const { handleRequest } = createGatewayRuntime({
|
||||
/* Your configuration here before the following required settings */
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ create a new server route in `my-project/src/routes/graphql/+server.ts` to expos
|
|||
at `/graphql` and implement using the Hive Gateway runtime like this:
|
||||
|
||||
```ts filename="my-project/src/routes/graphql/+server.ts"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const serve = createGatewayRuntime({
|
||||
supergraph: 'supergraph.graphql', // working directory is root of the project
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ with a simple configuration.
|
|||
|
||||
```ts filename="index.ts"
|
||||
import { App, HttpRequest, HttpResponse } from 'uWebSockets.js'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
interface ServerContext {
|
||||
req: HttpRequest
|
||||
|
|
@ -52,7 +52,7 @@ npm i graphql-ws
|
|||
import { execute, ExecutionArgs, subscribe } from 'graphql'
|
||||
import { makeBehavior } from 'graphql-ws/lib/use/uWebSockets'
|
||||
import { App, HttpRequest, HttpResponse } from 'uWebSockets.js'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
interface ServerContext {
|
||||
req: HttpRequest
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ other JS runtime with Hive Gateway;
|
|||
The following code is a simple example of how to use Hive Gateway with Bun.
|
||||
|
||||
```ts
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const gatewayRuntime = createGatewayRuntime(/* Your configuration */)
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ Create a `deno-hive-gateway.ts` file:
|
|||
|
||||
```ts filename="deno-hive-gateway.ts"
|
||||
import { serve } from 'https://deno.land/std@0.157.0/http/server.ts'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const gatewayRuntime = createGatewayRuntime(/* Your configuration */)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Callout } from '@theguild/components'
|
|||
For Node.js and other Node-compliant environments, you can use Gateway CLI as described in the
|
||||
[Node.js guide](/docs/gateway/deployment/runtimes/nodejs). But if you want to use Hive Gateway with
|
||||
a server-side JavaScript environment that is not compatible with Node.js API, you can use the
|
||||
`createGatewayRuntime` function from `@graphql-hive/gateway` package.
|
||||
`createGatewayRuntime` function from `@graphql-hive/gateway-runtime` package.
|
||||
|
||||
In this case, you have to pass your serve configuration inside `createGatewayRuntime` instead of
|
||||
exporting it `gatewayConfig` from `gateway.config.ts` file.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Node.js is the most common runtime for JavaScript.
|
|||
|
||||
If you have Node.js environment, we highly recommend to use Hive Gateway with the CLI as described
|
||||
in the [introduction](/docs/gateway). If you really want to use the runtime in a customized way. You
|
||||
can use the `createGatewayRuntime` function from `@graphql-hive/gateway` package.
|
||||
can use the `createGatewayRuntime` function from `@graphql-hive/gateway-runtime` package.
|
||||
|
||||
## Hive Gateway CLI
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ most cases.
|
|||
|
||||
```ts
|
||||
import { createServer } from 'http'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const serveRuntime = createGatewayRuntime(/* Your configuration */)
|
||||
const server = createServer(serveRuntime)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ See [Bundling Problems](/docs/gateway/deployment/serverless#bundling-problem) fo
|
|||
how to load the supergraph and `transports` option.
|
||||
|
||||
```js filename="gateway.ts"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import http from '@graphql-mesh/transport-http'
|
||||
import supergraph from './supergraph.js'
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ how to load the supergraph and `transports` option.
|
|||
|
||||
```ts
|
||||
import { app } from '@azure/functions'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import http from '@graphql-mesh/transport-http'
|
||||
import supergraph from './supergraph'
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ this makes sure that the Hive Gateway is gracefully and properly disposed before
|
|||
worker.
|
||||
|
||||
```ts filename="index.js"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import http from '@graphql-mesh/transport-http'
|
||||
import supergraph from './supergraph'
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ Hive Gateway can be deployed on the edge. This means that you can deploy your Hi
|
|||
serverless environment like AWS Lambda, Cloudflare Workers, or Azure Functions.
|
||||
|
||||
For Serverless environments, you cannot use Gateway CLI `hive-gateway` but you can use the
|
||||
`createGatewayRuntime` function from `@graphql-hive/gateway` package.
|
||||
`createGatewayRuntime` function from `@graphql-hive/gateway-runtime` package.
|
||||
|
||||
<Callout>
|
||||
Please read carefully following sections, most importantly [Bundling
|
||||
|
|
@ -24,7 +24,7 @@ See
|
|||
for more details.
|
||||
|
||||
```js filename="index.js"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
|
||||
const gateway = createGatewayRuntime({
|
||||
// Here any config available in `gateway.config.ts`.
|
||||
|
|
@ -64,7 +64,7 @@ transports needed to comunicate with your upstream services. This way, the trans
|
|||
statically referenced and will be included into the bundle.
|
||||
|
||||
```ts filename="index.ts"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import http from '@graphql-mesh/transport-http'
|
||||
import supergraph from './supergraph'
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ For this, we will need to have our supergraph SDL in a `.js` or a `.ts` file, so
|
|||
it in our script.
|
||||
|
||||
```ts
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway'
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import http from '@graphql-mesh/transport-http'
|
||||
import supergraph from './supergraph.js'
|
||||
|
||||
|
|
|
|||
|
|
@ -86,18 +86,27 @@ Gateway. [Learn more about KV](https://developers.cloudflare.com/workers/runtime
|
|||
documentation](/docs/gateway/deployment/serverless/cloudflare-workers).
|
||||
</Callout>
|
||||
|
||||
```ts filename="gateway.config.ts"
|
||||
import { defineConfig } from '@graphql-hive/gateway'
|
||||
```ts filename="index.ts"
|
||||
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
|
||||
import CloudflareKVCacheStorage from '@graphql-mesh/cache-cfw-kv'
|
||||
|
||||
export const gatewayConfig = defineConfig({
|
||||
cache: {
|
||||
type: 'cfw-kv',
|
||||
namespace: 'HiveGateway' // The namespace of the KV
|
||||
export default {
|
||||
fetch(request, env, ctx) {
|
||||
const gateway = createGatewayRuntime({
|
||||
supergraph,
|
||||
transports: { http },
|
||||
responseCaching: {
|
||||
session: () => null
|
||||
},
|
||||
cache: new CloudflareKVCacheStorage({
|
||||
logger,
|
||||
namespace: env.NAMESPACE
|
||||
})
|
||||
})
|
||||
ctx.waitUntil(gateway[Symbol.asyncDispose]())
|
||||
return gateway(request, env, ctx)
|
||||
}
|
||||
responseCaching: {
|
||||
session: () => null
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Custom Cache Storage
|
||||
|
|
|
|||
Loading…
Reference in a new issue