This package allows you to easily integrate Apollo Server with your h3 or Nuxt 3 application.
For defining a GraphQL server in Nuxt 3, you may want to have a look at the GraphQL server toolkit Nuxt module.
# npm
npm install @apollo/server graphql @as-integrations/h3
# yarn
yarn add @apollo/server graphql @as-integrations/h3
# pnpm
pnpm add @apollo/server graphql @as-integrations/h3
Create a Server API Route that configures an instance of Apollo Server as described in the documentation and then exports it as the event handler:
import { ApolloServer } from '@apollo/server'
import { startServerAndCreateH3Handler } from '@as-integrations/h3'
const apollo = new ApolloServer({
// Specify server options like schema and resolvers here
})
export default startServerAndCreateH3Handler(apollo, {
// Optional: Specify context
context: (event) => {...}
})
Create and configure an instance of Apollo Server as described in the documentation and then register it as a route handler in your h3
application.
import { createApp } from 'h3'
import { ApolloServer } from '@apollo/server'
import { startServerAndCreateH3Handler } from '@as-integrations/h3'
const apollo = new ApolloServer({
// Specify server options like schema and resolvers here
})
export const app = createApp()
app.use(
'/api',
startServerAndCreateH3Handler(apollo, {
// Optional: Specify context
context: (event) => {...}
})
)
Then run your h3 server as usual, e.g. with npx --yes listhen -w --open ./app.ts
.
Visit http://localhost:3000/api in your browser to access the Apollo Sandbox.
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10). - Install dependencies using
pnpm install
. - Run tests using
pnpm test
and integration tests viapnpm test:integration
.
Made with 💛
Published under MIT License.