0.10.0 • Published 2 years ago

next-graphql-server v0.10.0

Weekly downloads
-
License
Apache 2.0
Repository
-
Last release
2 years ago

next-graphql-server

next-graphql-server is an easy to use Next.js library for creating performant GraphQL endpoints on top of Next.js API Routes.

Start building GraphQL servers with Next.js.

Features

  • built using Envelop and Helix - stackable and easy to extend architecture
  • supports Vercel Edge functions

Getting Started

Create a Next.js project:

pnpm create next-app --typescript

Add next-graphql-server as a dependency to your Next.js project:

pnpm add next-graphql-server

Note: pnpm is preferred, but you can also use npm or yarn

npm install next-graphql-server
yarn add next-graphql-server

Usage

next-graphql-server uses Next.js API Routes. Create the pages/api/graphql.ts with the following content:

Note: The file in pages/api must be named graphql

with graphql

Add graphql

pnpm add graphql
import { createGraphQLHandler } from "next-graphql-server";
import {
  GraphQLObjectType,
  GraphQLSchema,
  GraphQLString,
} from "graphql";

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: "Query",
    fields: () => ({
      hello: {
        type: GraphQLString,
        resolve: () => "world",
      },
    }),
  }),
});

const handler = createGraphQLHandler(schema);
export default handler;

with @graphql-tools

Add @graphql-tools/schema

pnpm add @graphql-tools/schema

In pages/api/graphql.ts define your handler as shown below:

import { createGraphQLHandler } from "next-graphql-server";
import { makeExecutableSchema } from "@graphql-tools/schema";

export const schema = makeExecutableSchema({
  typeDefs: /* GraphQL */ `
    type Query {
      hello: String!
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'World',
    },
  },
});

const handler = createGraphQLHandler(schema);
export default handler;

with Pothos

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.1

2 years ago

0.9.1

2 years ago

0.5.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.4.0

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago