Skip to content

shawub/apollo-server-kuzzle

Repository files navigation

Apollo Kuzzle Middleware Integration

Apollo Server is designed to run as standalone, or deployed in any supporting node.js framework.

This package provides an integration for Kuzzle middleware.

Kuzzle

To add a graphql endpoint to kuzzle, implement a plugin

import { ApolloServer } from 'apollo-server-kuzzle';
import { JSONObject, PluginContext, Plugin, KuzzleRequest } from 'kuzzle';

export class MyPlugin extends Plugin {
  constructor() {
    super({ kuzzleVersion: '>=2.8.0 <3' });
  }

  async init(config: JSONObject, context: PluginContext): Promise<void> {
    this.config = config;
    this.context = context;
    // define types and resolvers
    const typeDefs = gql`
      type Query {
        hello: String
      }
    `;

    const resolvers = {
      Query: {
        hello: () => 'Hello world!',
      },
    };
    // instantiate `server`
    const server = new ApolloServer({ typeDefs, resolvers });
    await server.start();
    // create a request handler
    const handler = await apolloServer.createHandler();

    // install myApi controller
    this.api = {
      myApi: {
        actions: {
          graphql: {
            handler,
            http: [
              {
                verb: 'post',
                path: '/gapqhl',
              },
            ],
          },
        },
      },
    };
  }
}

Then install the plugin in the kuzzle app.

app.plugin.use(new MyPlugin());

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published