@cfpreview/pages-plugins-graphql
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

Pages Plugins

GraphQL

This GraphQL plugin creates a GraphQL server which can respond to application/json and application/graphql POST requests. It responds with the GraphQL Playground for GET requests.

Installation

npm install --save @cfpreview/pages-plugins-graphql

Usage

// ./functions/graphql.ts

import graphQLPlugin from "@cfpreview/pages-plugins-graphql";
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql";

const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: "RootQueryType",
    fields: {
      hello: {
        type: GraphQLString,
        resolve() {
          return "Hello, world!";
        },
      },
    },
  }),
});

export const onRequest: PagesFunction = graphQLPlugin({
  schema,
});

This plugin only exposes a single route, so wherever it is mounted is wherever it will be available. In the above example, because it is mounted in ./functions/graphql.ts the server will be available on /graphql of the app.

Readme

Keywords

none

Package Sidebar

Install

npm i @cfpreview/pages-plugins-graphql

Weekly Downloads

169

Version

0.1.1

License

none

Unpacked Size

15.8 kB

Total Files

6

Last publish

Collaborators

  • gregbrimble
  • 1000hz
  • geelen