-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgraphql-query.ts
More file actions
74 lines (61 loc) · 1.6 KB
/
Copy pathgraphql-query.ts
File metadata and controls
74 lines (61 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { ApolloServer, gql } = require('apollo-server-lambda');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const AWSXRay = require('aws-xray-sdk-core');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
const REQUEST_EVENT_DETAIL_TYPE = process.env.REQUEST_EVENT_DETAIL_TYPE!;
const eventBridge = new AWS.EventBridge({
region: process.env.AWS_REGION,
});
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type EventDetails {
EventId: String
ErrorMessage: String
ErrorCode: String
}
type Mutation {
putEvent(message: String!, chatId: String!): Result
}
type Query {
getEvent: String
}
type Result {
Entries: [EventDetails]
FailedEntries: Int
}
type Subscription {
chat(chatId: String!): String
}
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Mutation: {
// tslint:disable-next-line:no-any
putEvent: async (_: any, { message, chatId }: any) => eventBridge.putEvents({
Entries: [
{
EventBusName: process.env.BUS_NAME,
Source: 'apollo',
DetailType: REQUEST_EVENT_DETAIL_TYPE,
Detail: JSON.stringify({
message,
chatId,
}),
},
],
}).promise(),
},
Query: {
getEvent: () => 'Hello from Apollo!',
},
};
export const schema = makeExecutableSchema({ typeDefs, resolvers });
const server = new ApolloServer({
schema,
});
export const mutationAndQueryHandler = server.createHandler();