How to use the apollo-server-micro.makeExecutableSchema function in apollo-server-micro

To help you get started, we’ve selected a few apollo-server-micro examples, based on popular ways it is used in public projects.

github fanout / fanout-graphql-tools / examples / micro / src / index.ts View on Github external
IStoredPubSubSubscription,
  WebSocketOverHttpContextFunction,
} from "fanout-graphql-tools";
import { MapSimpleTable } from "fanout-graphql-tools";
import * as http from "http";
import micro from "micro";
import { SimpleGraphqlApi } from "../../../src/simple-graphql-api/SimpleGraphqlApi";

/**
 * WebSocket-Over-HTTP Support requires storage to keep track of ws-over-http connections and subscriptions.
 * The Storage objects match an ISimpleTable interface that is a subset of the @pulumi/cloud Table interface. MapSimpleTable is an in-memory implementation, but you can use @pulumi/cloud implementations in production, e.g. to use DyanmoDB.
 */
const connectionStorage = MapSimpleTable<IStoredConnection>();
const pubSubSubscriptionStorage = MapSimpleTable<IStoredPubSubSubscription>();

const schema = makeExecutableSchema(SimpleGraphqlApi());

const apolloServer = new ApolloServer({
  context: WebSocketOverHttpContextFunction({
    grip: {
      // Get this from your Fanout Cloud console, which looks like https://api.fanout.io/realm/{realm-id}?iss={realm-id}&key=base64:{realm-key}
      // or use this localhost for your own pushpin.org default installation
      url: process.env.GRIP_URL || "http://localhost:5561",
    },
    pubSubSubscriptionStorage,
    schema,
  }),
  schema,
});

// Note: In micro 9.3.5 this will return an http.RequestListener instead (after https://github.com/zeit/micro/pull/399)
// Provide it to http.createServer to create an http.Server

apollo-server-micro

Production-ready Node.js GraphQL server for Micro

MIT
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis

Similar packages