How to use aws-lambda-graphql - 10 common examples

To help you get started, we’ve selected a few aws-lambda-graphql 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 michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
await pubSub.publish('NEW_MESSAGE', payload);

      return payload;
    },
  },
  Query: {
    serverTime: () => Date.now(),
  },
  Subscription: {
    messageFeed: {
      resolve: (rootValue: Message) => {
        // root value is the payload from sendMessage mutation
        return rootValue;
      },
      subscribe: withFilter(
        pubSub.subscribe('NEW_MESSAGE'),
        (rootValue: Message, args: { type: null | MessageType }) => {
          // this can be async too :)
          if (args.type == null) {
            return true;
          }

          return args.type === rootValue.type;
        },
      ),
    },
  },
};

const server = new Server({
  connectionManager,
github michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
(rootValue: Message, args: { type: null | MessageType }) => {
          // this can be async too :)
          if (args.type == null) {
            return true;
          }

          return args.type === rootValue.type;
        },
      ),
    },
  },
};

const server = new Server({
  connectionManager,
  eventProcessor: new DynamoDBEventProcessor(),
  resolvers,
  subscriptionManager,
  typeDefs,
});

export const handleHttp = server.createHttpHandler();
export const handleWebSocket = server.createWebSocketHandler();
export const handleDynamoDBStream = server.createEventHandler();
github michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
subscribe: withFilter(
        pubSub.subscribe('NEW_MESSAGE'),
        (rootValue: Message, args: { type: null | MessageType }) => {
          // this can be async too :)
          if (args.type == null) {
            return true;
          }

          return args.type === rootValue.type;
        },
      ),
    },
  },
};

const server = new Server({
  connectionManager,
  eventProcessor: new DynamoDBEventProcessor(),
  resolvers,
  subscriptionManager,
  typeDefs,
});

export const handleHttp = server.createHttpHandler();
export const handleWebSocket = server.createWebSocketHandler();
export const handleDynamoDBStream = server.createEventHandler();
github michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
const apiGatewayManager = new ApiGatewayManagementApi({
  ...(process.env.IS_OFFLINE
    ? {
        endpoint: 'http://localhost:3001',
      }
    : {}),
});
const dynamoDbClient = new DynamoDB.DocumentClient({
  ...(process.env.IS_OFFLINE
    ? {
        endpoint: 'http://localhost:8000',
      }
    : {}),
});

const eventStore = new DynamoDBEventStore({ dynamoDbClient });
const pubSub = new PubSub({ eventStore });
const subscriptionManager = new DynamoDBSubscriptionManager({ dynamoDbClient });
const connectionManager = new DynamoDBConnectionManager({
  apiGatewayManager,
  dynamoDbClient,
  subscriptions: subscriptionManager,
});

type MessageType = 'greeting' | 'test';

type Message = {
  id: string;
  text: string;
  type: MessageType;
};
github michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
...(process.env.IS_OFFLINE
    ? {
        endpoint: 'http://localhost:3001',
      }
    : {}),
});
const dynamoDbClient = new DynamoDB.DocumentClient({
  ...(process.env.IS_OFFLINE
    ? {
        endpoint: 'http://localhost:8000',
      }
    : {}),
});

const eventStore = new DynamoDBEventStore({ dynamoDbClient });
const pubSub = new PubSub({ eventStore });
const subscriptionManager = new DynamoDBSubscriptionManager({ dynamoDbClient });
const connectionManager = new DynamoDBConnectionManager({
  apiGatewayManager,
  dynamoDbClient,
  subscriptions: subscriptionManager,
});

type MessageType = 'greeting' | 'test';

type Message = {
  id: string;
  text: string;
  type: MessageType;
};

type SendMessageArgs = {
github michalkvasnicak / aws-lambda-graphql / packages / chat-example-server / src / index.ts View on Github external
endpoint: 'http://localhost:3001',
      }
    : {}),
});
const dynamoDbClient = new DynamoDB.DocumentClient({
  ...(process.env.IS_OFFLINE
    ? {
        endpoint: 'http://localhost:8000',
      }
    : {}),
});

const eventStore = new DynamoDBEventStore({ dynamoDbClient });
const pubSub = new PubSub({ eventStore });
const subscriptionManager = new DynamoDBSubscriptionManager({ dynamoDbClient });
const connectionManager = new DynamoDBConnectionManager({
  apiGatewayManager,
  dynamoDbClient,
  subscriptions: subscriptionManager,
});

type MessageType = 'greeting' | 'test';

type Message = {
  id: string;
  text: string;
  type: MessageType;
};

type SendMessageArgs = {
  text: string;
  type: MessageType;