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.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

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();
const pubSubSubscriptionStorage = MapSimpleTable();

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