1.1.6 • Published 9 months ago

@as-integrations/h3 v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Apollo Server integration for h3 and nuxt

npm version npm downloads Github Actions Codecov

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.

Installation

# 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

Usage with Nuxt v3

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 here
})

export default startServerAndCreateH3Handler(apollo, {
  // Optional: Specify context
  context: (event) => {...}
})

Usage with h3

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, toNodeListener } from 'h3'
import { ApolloServer } from '@apollo/server'
import { startServerAndCreateH3Handler } from '@as-integrations/h3'

const apollo = new ApolloServer({
  // Specify server options here
})

const app = createApp()
app.use(
  '/api',
  startServerAndCreateH3Handler(apollo, {
    // Optional: Specify context
    context: (event) => {...}
  })
)

createServer(toNodeListener(app)).listen(process.env.PORT || 3000)

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10).
  • Install dependencies using pnpm install.
  • Run tests using pnpm test and integration tests via pnpm test:integration.

License

Made with 💛

Published under MIT License.

1.1.6

9 months ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago