Pup

v2.x

GraphQLPupQL

To aid in the process of setting up a GraphQL server and connecting it to your app, Pup ships with an implementation of the @cleverbeagle/pupql package.

This package is designed to attach a GraphQL schema to an existing server instance and set up a WebSocket connection for subscriptions.

PupQL is pre-configured in Pup so there's nothing you need to do to make it work. Of note, PupQL is configured to:

  • Automatically pass your current user (if one exists) to all of your Query and Mutation resolvers in your GraphQL schema via the context argument (context.user).
  • Run a GraphQL server on top of your existing Meteor web server (e.g., if your app runs at http://localhost:3000, PupQL will attach your GraphQL server at http://localhost:3000/graphql).
  • Starts a GraphQL subscription server on http://localhost:4001 (e.g., PupQL will run your subscription server at ws://localhost:4001/graphql).
/startup/server/graphql.js
import pupql from '@cleverbeagle/pupql';
import { WebApp } from 'meteor/webapp';
import { getUser } from 'meteor/apollo';
import schema from './api';

pupql({
  schema,
  databases: {
    mongodb: {
      connectionString: process.env.MONGO_URL,
    },
  },
  context: async ({ req }) => ({
    user: await getUser(req.headers.authorization),
  }),
  config: {
    existingWebServer: WebApp.connectHandlers,
  },
});