Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-graphql

Package Overview
Dependencies
Maintainers
2
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-graphql

GraphQL for Next.js

  • 2.0.20
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-85%
Maintainers
2
Weekly downloads
 
Created
Source

NOTE - next-graphql is still in alpha and not suitable for production environments yet.

Overview

GraphQL for Next.js

Introduction

NextGraphQL.js is a zero-config GraphQL server for Next.js, designed to run as a serverless function or standalone server.

It supports a lot of extras right out of the box:

  • schema stitching and merging
  • authentication + NextAuth support
  • automatic code generation
  • RBAC + guards
  • ... and more!

Quickstart

Run npx next-graphql init in the base Next.js project folder.

Then, open http://localhost:3000/api/graphql. That's it.

Getting Started

@todo

Adding Queries and Mutations

@todo

Schema Configuration

@todo

Remote Schemas

@todo

// ./graphql/server/config.ts

import { nextHandler, remote } from "next-graphql"

export const handler = () => {
  return nextHandler({
    schemas: {
      graphcms: remote(process.env.GRAPHCMS_URL, {
        headers: {
          Authorization: "Bearer " + process.env.GRAPHCMS_TOKEN,
        },
      }),
    },
  })
}

Project Structure

The init command will add the following to to your project structure:

./{nextroot}
│
├── graphql
│   ├── client
│   │   ├── fragments.graphql
│   │   ├── operations.graphql
│   │   └── codegen.yml
│   └── server
│       ├── overrides.ts
│       └── config.ts
└── pages
    ├── api
    │   └── graphql.ts
    └── ...

./graphql/client

This is the base directory for the graphql-code-generator configuration.

Feel free to organize this folder however you'd like, fragments + operations files are a suggestions. All configuration is run off the codegen.yml so make sure edit this file if you make changes to the folder structure.

NextGraphQL.js seeks to simply setup the structure for code generation, but remains unopinionated on the matter of picking a frontend GraphQL client.

The repository author's personal favorite is URQL. Provides idiomatic integrations into React, Svelte, and Vue and is really easy to use.

Other suggestions:

For a reference on all GraphQL Code Generator plugins, see all graphql-code-generator plugins.

./graphql/server/config.js

import { nextHandler, remote } from "next-graphql"

export const handler = () => {
  return nextHandler({
    schemas: {
      // ... add your schemas here
    },
  })
}

For more information on configuring schemas, see schema configuration.

./pages/api/graphql.ts

Binds the server to a Next.js API endpoint

import { handler } from "../../graphql/server/config"

// Make sure you keep this line
export const config = {
  api: {
    bodyParser: false,
  },
}

export default handler()

FAQs

Package last updated on 18 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc