@chillicream/bananacakepop-server-adapter-plugin
TypeScript icon, indicating that this package has built-in type declarations

17.0.0 • Public • Published

Banana Cake Pop Server Adapter Plugin

Server Adapter Plugin for Banana Cake Pop GraphQL IDE

Description

This plugin allows to setup Banana Cake Pop GraphQL IDE for your GraphQL Yoga server or any other server that implements the Server Adapter (see @whatwg-node).

You can use a cdn hosted version of the app or a self hosted version using the ad hoc package.

Installation

Install this package and the required peerDependencies in your project:

npm install @chillicream/bananacakepop-server-adapter-plugin --save-dev
# or
yarn add @chillicream/bananacakepop-server-adapter-plugin --dev
# or
pnpm add @chillicream/bananacakepop-server-adapter-plugin --save-dev

Note: @chillicream/bananacakepop-graphql-ide is optional and only needed if you prefer to self host the app.

Usage

Add the plugin to your server.

import { useBananaCakePop } from "@chillicream/bananacakepop-server-adapter-plugin";
import { createYoga } from "graphql-yoga";
import { createServer } from "node:http";

const yoga = createYoga({
  schema: // Schema omitted for brevity,
  plugins: [useBananaCakePop()], // Adds Banana Cake Pop
  graphiql: false, // Disables the default GraphQL IDE
});

const server = createServer(yoga);

server.listen(3000, () => {
  console.log("Running a GraphQL API server at http://localhost:3000/graphql");
});

Extended configuration

  • To pin a specific version instead of using "latest":

    useBananaCakePop({
      mode: "cdn",
      target: { version: "x.0.0" },
    });
  • To use your own infrastructure:

    useBananaCakePop({
      mode: "cdn",
      target: "https://mycompany.com/bcp",
    });

Custom options

  • To pass options supported by Banana Cake Pop GraphQL IDE:

    useBananaCakePop({
      mode: "cdn",
      options: {
        title: "BCP",
      },
    });

Recipes

🔗 With graphql-yoga
import { useBananaCakePop } from "@chillicream/bananacakepop-server-adapter-plugin";
import { createYoga } from "graphql-yoga";
import { createServer } from "node:http";

const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        greeting: String
      }
    `,
    resolvers: {
      Query: {
        greeting: () => "Hello, World!",
      },
    },
  }),
  plugins: [useBananaCakePop()], // Adds Banana Cake Pop
  graphiql: false, // Disables the default GraphQL IDE
});

const server = createServer(yoga);

server.listen(3000, () => {
  console.log("Running a GraphQL API server at http://localhost:3000/graphql");
});

🔗 With graphql-yoga and grats
import { useBananaCakePop } from "@chillicream/bananacakepop-server-adapter-plugin";
import { createYoga, createSchema } from "graphql-yoga";
import { createServer } from "node:http";
import { getSchema } from "./schema"; // Will be generated by Grats

/** @gqlType */
type Query = unknown;

/** @gqlField */
export function hello(_: Query): string {
  return "Hello world!";
}

const yoga = createYoga({
  schema: getSchema(),
  plugins: [useBananaCakePop()], // Adds Banana Cake Pop
  graphiql: false, // Disables the default GraphQL IDE
});

const server = createServer(yoga);

server.listen(3000, () => {
  console.log("Running a GraphQL API server at http://localhost:3000/graphql");
});

Package Sidebar

Install

npm i @chillicream/bananacakepop-server-adapter-plugin

Weekly Downloads

6

Version

17.0.0

License

SEE LICENSE FILE

Unpacked Size

26.3 kB

Total Files

7

Last publish

Collaborators

  • rafaelstaib