GraphQL Apollo plugin
Plugin for elysia for using GraphQL Apollo.
Install with:
bun add graphql @elysia/apollo@next @apollo/serverThen use it:
import { Elysia } from 'elysia'import { apollo, gql } from '@elysia/apollo'
const app = new Elysia() .use( apollo({ typeDefs: gql` type Book { title: String author: String }
type Query { books: [Book] } `, resolvers: { Query: { books: () => { return [ { title: 'Elysia', author: 'saltyAom' } ] } } } }) ) .listen(3000)Accessing /graphql should show the Apollo GraphQL playground to work with.
Context
Section titled “Context”The context callback receives the Elysia context, so read request from it.
const app = new Elysia() .use( apollo({ typeDefs, resolvers, context: async ({ request }) => { const authorization = request.headers.get('Authorization')
return { authorization } } }) ) .listen(3000)Config
Section titled “Config”This plugin extends Apollo’s ApolloServerOptions (which is ApolloServer’s constructor parameter).
Below are the extended parameters for configuring Apollo Server with Elysia.
Default: "/graphql"
Path to expose Apollo Server.
enablePlayground
Section titled “enablePlayground”Default: process.env.ENV !== 'production'
Determine whether Apollo should provide Apollo Playground.