-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (93 loc) · 2.81 KB
/
index.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { EnvelopArmorPlugin } from "@escape.tech/graphql-armor";
import { http } from "@google-cloud/functions-framework";
import LocalforageCache from "@graphql-mesh/cache-localforage";
import useHive from "@graphql-mesh/plugin-hive";
import useMeshResponseCache from "@graphql-mesh/plugin-response-cache";
import { createServeRuntime } from "@graphql-mesh/serve-runtime";
import { PubSub } from "@graphql-mesh/utils";
import { useJWT } from "@graphql-yoga/plugin-jwt";
import packageInfo from "./package.json" with { type: "json" };
if (!process.env.HIVE_TOKEN) {
throw new Error("HIVE_TOKEN is required");
}
if (!process.env.UPSTREAM) {
throw new Error("UPSTREAM is required");
}
const meshHTTP = createServeRuntime({
cache: new LocalforageCache(),
pubsub: new PubSub(),
landingPage: false,
graphqlEndpoint: "/",
proxy: {
endpoint: process.env.UPSTREAM,
headers: (ctx) => ({
Authorization: ctx.context.request
? ctx.context.request.headers.get("Authorization")
: undefined,
"x-hasura-admin-secret": ctx.context.request
? undefined
: process.env.HASURA_ADMIN_SECRET,
}),
},
maskedErrors: false,
plugins: (ctx) => {
const armorLogger = ctx.logger.child("Armor");
return [
useJWT({
algorithms: ["RS256"],
issuer: "https://securetoken.google.com/ffxivteamcraft",
audience: "ffxivteamcraft",
jwksUri:
"https://www.googleapis.com/service_accounts/v1/jwk/[email protected]",
}),
useHive({
...ctx,
logger: ctx.logger.child("Hive"),
token: process.env.HIVE_TOKEN,
enabled: true,
reporting: {
author: packageInfo.author,
commit: packageInfo.version,
},
usage: {
clientInfo: {
name: "ffxivteamcraft",
version: packageInfo.version,
},
sampleRate: 0.1,
},
}),
useMeshResponseCache({
...ctx,
sessionId: null, // Global cache
includeExtensionMetadata: true,
ttl: 10 * 60 * 1000,
ignoredTypes: ['allagan_reports', 'allagan_reports_aggregate', 'allagan_reports_queue', 'allagan_reports_queue_aggregate', 'allagan_reports_queue_per_item']
}),
EnvelopArmorPlugin({
maxDepth: {
n: 20,
onReject: armorLogger.error,
},
costLimit: {
maxCost: 10000,
depthCostFactor: 1,
scalarCost: 0,
onReject: armorLogger.error,
},
maxAliases: {
n: 110,
allowList: [],
onReject: armorLogger.error,
},
maxDirectives: {
onReject: armorLogger.error,
},
maxTokens: {
onReject: armorLogger.error,
},
}),
];
},
});
http("graphql", meshHTTP);