0.13.1 • Published 5 years ago
aws-lambda-graphql v0.13.1
AWS Lambda GraphQL Server and Client with subscriptions support
GraphQL server and client implementation for AWS Lambda with WebSocket support (API Gateway v2).
Installation
npm install aws-lamda-graphql apollo-link graphql graphql-subscriptions
# or
yarn add aws-lambda-graphql apollo-link graphql graphql-subscriptions
Usage
Implement your simple server using DynamoDB stream as PubSub backend
const {
createDynamoDBEventProcessor,
createWsHandler,
DynamoDBConnectionManager,
DynamoDBEventStore,
DynamoDBSubscriptionManager,
PubSub,
} = require('aws-lambda-graphql');
import { makeExecutableSchema } from 'graphql-tools';
// this only processes AWS Api Gateway v2 events
// if you want to process HTTP too, use createHttpHandler
// or you can use both, see chat-example-server
// instantiate event store
// by default uses Events table (can be changed)
const eventStore = new DynamoDBEventStore();
const pubSub = new PubSub({ eventStore });
const subscriptionManager = new DynamoDBSubscriptionManager();
const connectionManager = new DynamoDBConnectionManager({
subscriptions: subscriptionManager,
});
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Mutation {
publish(message: String!): String!
}
type Query {
dummy: String!
}
type Subscription {
messageFeed: String!
}
`,
resolvers: {
Query: {
dummy: () => 'dummy',
},
Mutation: {
publish: async (rootValue, { message }) => {
await pubSub.publish('NEW_MESSAGE)', { message });
return message;
},
},
Subscription: {
messageFeed: {
// rootValue is same as object published using pubSub.publish
resolve: rootValue => rootValue.message,
subscribe: pubSub.subscribe('NEW_MESSAGE'),
},
},
},
});
const eventProcessor = createDynamoDBEventProcessor({
connectionManager,
schema,
subscriptionManager,
});
const wsHandler = createWsHandler({
context: ({ event }) => ({
event, // current processed event (see IContext)
}),
connectionManager,
schema,
subscriptionManager,
// validationRules
});
// use these handlers from your lambda and map them to
// api gateway v2 and DynamoDB events table
module.exports.consumeWsEvent = wsHandler;
module.exports.consumeDynamoDBStream = eventProcessor;
Examples
- Chat App - React app
- Chat Server
- contains AWS Lambda that handles HTTP, WebSocket and DynamoDB streams
- also includes serverless.yaml file for easy deployment
1.0.0-alpha.24
4 years ago
1.0.0-alpha.23
4 years ago
1.0.0-alpha.22
4 years ago
1.0.0-alpha.21
4 years ago
1.0.0-alpha.20
4 years ago
1.0.0-alpha.19
5 years ago
1.0.0-alpha.18
5 years ago
1.0.0-alpha.17
5 years ago
1.0.0-alpha.16
5 years ago
1.0.0-alpha.15
5 years ago
1.0.0-alpha.14
5 years ago
1.0.0-alpha.13
5 years ago
1.0.0-alpha.12
5 years ago
1.0.0-alpha.11
5 years ago
1.0.0-alpha.10
5 years ago
1.0.0-alpha.9
5 years ago
1.0.0-alpha.8
5 years ago
1.0.0-alpha.7
5 years ago
1.0.0-alpha.6
5 years ago
0.13.1
5 years ago
1.0.0-alpha.5
5 years ago
1.0.0-alpha.4
5 years ago
1.0.0-alpha.3
5 years ago
1.0.0-alpha.2
5 years ago
1.0.0-alpha.1
5 years ago
1.0.0-alpha.0
5 years ago
0.13.0
6 years ago
0.12.3
6 years ago
0.12.2
6 years ago
0.12.1
6 years ago
0.12.0
6 years ago
0.11.0
6 years ago
0.10.0
6 years ago
0.9.1
6 years ago
0.9.0
6 years ago
0.8.1
6 years ago
0.8.0
6 years ago
0.7.2
6 years ago
0.7.1
6 years ago
0.7.0
6 years ago
0.6.0
6 years ago
0.5.0
6 years ago
0.4.0
6 years ago
0.3.1
6 years ago
0.3.0
6 years ago
0.2.1
6 years ago
0.2.0
6 years ago
0.1.0
6 years ago
0.1.0-alpha.0
6 years ago