Integration with SvelteKit

SvelteKit is a framework for rapidly developing robust, performant web applications using Svelte. You can easily integrate Hive Gateway into your SvelteKit powered application.

Example

SvelteKit is typically used together with Vite with the project structure looking like this. We also assume that you have composed a supergraph.graphql with GraphQL Mesh.

In this example, we want to integrate Hive Gateway into Vite’s routes, we’ll therefore use the runtime.

npm i @graphql-hive/gateway-runtime

Keeping the aforementioned project layout in mind, create a new server route in my-project/src/routes/graphql/+server.ts to expose the GraphQL server at /graphql and implement using the Hive Gateway runtime like this:

my-project/src/routes/graphql/+server.ts
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
 
const serve = createGatewayRuntime({
  supergraph: 'supergraph.graphql', // working directory is root of the project
  graphqlEndpoint: '/graphql', // matches the server route path
  fetchAPI: { Response } // use the native `Response`
})
 
export { serve as GET, serve as POST }