0.5.1 • Published 3 years ago

@ev-fns/graphql v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@ev-fns/graphql

Apollo Server wrapper

  • createApollo
  • resolver
  • subscription

Install

yarn add express graphql apollo-server-core @ev-fns/graphql

Usage

const { gql } = require("apollo-server-core");
const express = require("express");
const http = require("http");
const { createApollo, resolver, subscription } = require("@ev-fns/graphql");

const quotes = [];

const typeDefs = gql`
  type Query {
    allQuotes: [String!]!
  }
  type Mutation {
    addQuote(quote: String!): String!
  }
  type Subscription {
    quoteAdded: String!
  }
`;

const resolvers = {
  Query: {
    allQuotes: resolver(async () => quotes),
  },
  Mutation: {
    addQuote: resolver(async (_, { quote }, { pubsub }) => {
      quotes.push(quote);
      pubsub.publish("quoteAdded", { quoteAdded: quote });
      return quote;
    }),
  },
  Subscription: {
    quoteAdded: subscription(async (_, args, { pubsub }) =>
      pubsub.asyncIterator("quoteAdded"),
    ),
  },
};

const app = express();

const apollo = createApollo({
  typeDefs,
  resolvers,
  context: () => ({}),
});

app.use(apollo.middleware);

const server = http.createServer(app);

apollo.installSubscriptions(server);

server.listen(3000, () => {
  console.log("listening at http://localhost:3000");
});
0.5.1

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago