21.0.2 • Published 9 months ago

@chillicream/nitro-server-adapter-plugin v21.0.2

Weekly downloads
-
License
SEE LICENSE FILE
Repository
github
Last release
9 months ago

Nitro Server Adapter Plugin

Server Adapter Plugin for Nitro GraphQL IDE

Description

This plugin allows to setup Nitro 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/nitro-server-adapter-plugin --save-dev
# or
yarn add @chillicream/nitro-server-adapter-plugin --dev
# or
pnpm add @chillicream/nitro-server-adapter-plugin --save-dev

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

Usage

Add the plugin to your server.

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

const yoga = createYoga({
  schema: // Schema omitted for brevity,
  plugins: [useNitro()], // Adds Nitro
  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":

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

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

Custom options

  • To pass options supported by Nitro GraphQL IDE:

    useNitro({
      mode: "cdn",
      options: {
        title: "Nitro",
      },
    });

Recipes

import { useNitro } from "@chillicream/nitro-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: [useNitro()], // Adds Nitro
  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");
});
import { useNitro } from "@chillicream/nitro-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: [useNitro()], // Adds Nitro
  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");
});
22.0.0-insider.1

9 months ago

21.0.2

9 months ago

21.0.1

9 months ago

21.0.0

9 months ago

21.0.0-insider.10

9 months ago

21.0.0-insider.6

9 months ago

21.0.0-insider.7

9 months ago

21.0.0-insider.8

9 months ago

21.0.0-insider.9

9 months ago

21.0.0-insider.5

9 months ago

21.0.0-insider.4

9 months ago

21.0.0-insider.3

9 months ago

20.0.2

9 months ago

21.0.0-insider.2

9 months ago

20.0.1

9 months ago

21.0.0-insider.1

9 months ago

20.0.0

9 months ago

20.0.0-insider.10

9 months ago

19.0.7

9 months ago

19.0.6

9 months ago

19.0.5

9 months ago

20.0.0-insider.5

9 months ago

19.0.4

9 months ago

20.0.0-insider.3

9 months ago

19.0.3

9 months ago

19.0.2

9 months ago

20.0.0-insider.2

9 months ago

20.0.0-insider.1

9 months ago

19.0.1

9 months ago

19.0.0

9 months ago

19.0.0-insider.6

9 months ago

19.0.0-insider.5

9 months ago

19.0.0-insider.4

9 months ago

19.0.0-insider.3

9 months ago

19.0.0-insider.2

9 months ago

19.0.0-insider.1

9 months ago