1.1.5 • Published 2 years ago

nextjs-apollo-server v1.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

nextjs-apollo-server

A small package to convert api routes in graphql using apollo server

Install

npm i nextjs-apollo-server@latest

Usage in Api routes

  • params config is same to new ApolloServer({ ...config })
  • you can change path, by default is /api/graphql
  • this package only added CORS to api route
  • export config is needed
// /api/graphql
import { apolloServer, type ApolloServerConfig } from 'nextjs-apollo-server'
import { type PageConfig } from 'next'

const { getServer } = apolloServer({
  config: {
    typeDefs: `
      type Query {
        hello: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'Hello world!',
      },
    },
  },
})

// https://nextjs.org/docs/api-routes/api-middlewares#custom-config
export const config: PageConfig = {
  api: {
    bodyParser: false,
  },
}

export default getServer

Usage in client

import { ApolloClient, InMemoryCache } from '@apollo/client'

export const client = new ApolloClient({
  uri: '/api/graphql', // your path from apollo server
  cache: new InMemoryCache(),
})
1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago