next-graphql-server is a library for building production-grade GraphQL servers using Next.js with API Routes

Overview

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

Install

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

Usage

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

with 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

You might also like...

Rollup + Babel + Prettier + Strict ESlint + VSCode - Enterprise grade boilerplate

Javascript package boilerplate by HackingBay Rollup + Babel + Prettier + Strict ESlint + VSCode - Enterprise grade boilerplate Minimalist js package b

Dec 28, 2021

Rollup + React + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterprise grade boilerplate

React package boilerplate by HackingBay Rollup + React 17 + Babel + Prettier + Strict ESlint and Stylelint + Sass + VSCode + Playground app - Enterpri

Jan 19, 2022

A framework dedicated to making it easier for you to build enterprise-grade PWA applications.

 A framework dedicated to making it easier for you to build enterprise-grade PWA applications.

A framework dedicated to making it easier for you to build enterprise-grade PWA applications.

Oct 6, 2022

🚏 Routes for Next.js

🚏 Routes for Next.js

next-route-map 🚏 next-route-map allows you to define a route map. It automatically generates page modules that forward original modules in build time

Sep 24, 2022

Monolithic repo for api server, image server, web server

Onsecondary Market Deployed at https://market.onsecondary.com Monolithic repo for api server, image server, web server TODO -use a script to cull expi

Jan 11, 2022

WPPConnect/WA-JS API SERVER is a small api server to provide url preview for @wppconnect/wa-js library

WPPConnect/WA-JS API SERVER WPPConnect/WA-JS API SERVER is a small api server to provide url preview for @wppconnect/wa-js library Our online channels

Aug 11, 2022

A Node.js REST API example built with Express and Typescript that can be used as template for creation of new servers.

api-example-firebase-nodejs A Node.js REST API example built with Express and Typescript that can be used as template for creation of new servers. The

Nov 25, 2022

A highly opinionated and complete starter for Next.js projects ready to production

A highly opinionated and complete starter for Next.js projects ready to production

The aim for this starter is to give you a starting point with everything ready to work and launch to production. Web Vitals with 100% by default. Folder structure ready. Tooling ready. SEO ready. SSR ready.

Nov 27, 2022

Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript

Ping.js Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript! This is useful for whe

Dec 27, 2022
Comments
  • Support contextFactory

    Support contextFactory

    Having context factory as a parameter is the only missing part of this package.

    Example implementation can be https://github.com/anonrig/bookclub/blob/main/src/lib/graphql/index.ts#L119

    opened by anonrig 3
Owner
Jakub Neander
Occasional JavaScript programmer. On a quest for the Holy Grail of Programming. But first I need to understand Self.
Jakub Neander
This package enables you to define your routes using the flat-routes convention.

Remix Flat Routes This package enables you to define your routes using the flat-routes convention. This is based on the gist by Ryan Florence ?? Insta

Kiliman 180 Jan 3, 2023
A tool for managing production-grade cloud clusters, infrastructure as code

Cloudy Description Cloudy is an "infrastructure as code" tool for managing production-grade cloud clusters. It's based on Pulumi that mostly using Ter

Cloudy 24 Jan 1, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Avoid CORS issues by using API Routes from Next.js

CORS Demo Avoid CORS issues by using API Routes from Next.js. Get Started Clone the repo git clone [email protected]:gregrickaby/cors-demo.git CD into co

Greg Rickaby 2 Sep 30, 2022
Proof of concept: support immutable trpc servers using lambdas to ensure client/server compatibility

auto-versioned-trpc-aws-lambda Proof of concept to support an automatically versioned AWS Lambda running tRPC to ensure a somewhat graceful and automa

Kenneth Skovhus 5 Aug 30, 2022
🛡️ Dead-simple, yet highly customizable security middleware for Apollo GraphQL servers and Envelop 🛡️

GraphQL Armor ??️ GraphQL Armor is a dead-simple yet highly customizable security middleware for various GraphQL server engines. Contents Contents Sup

Escape – GraphQL Security 267 Jan 9, 2023
Simple and customizable security middleware for GraphQL servers in Deno.

GuarDenoQL Simple and customizable security middleware for GraphQL servers in Deno Features Integrates with an Opine server in a Deno runtime. Enables

OSLabs Beta 43 Nov 5, 2022
Helps with math up to grade 10/11

Infinite-powers The code was written in p5js and the platform I used was CodePen. What the code does is that it provides help with different math topi

null 1 Jun 19, 2022