@effect-gql/core 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -0
- package/builder/index.cjs +1431 -0
- package/builder/index.cjs.map +1 -0
- package/builder/index.d.cts +259 -0
- package/{dist/builder/pipe-api.d.ts → builder/index.d.ts} +49 -21
- package/builder/index.js +1390 -0
- package/builder/index.js.map +1 -0
- package/index.cjs +3419 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +523 -0
- package/index.d.ts +523 -0
- package/index.js +3242 -0
- package/index.js.map +1 -0
- package/package.json +19 -28
- package/schema-builder-Cvdq7Kz_.d.cts +963 -0
- package/schema-builder-Cvdq7Kz_.d.ts +963 -0
- package/server/index.cjs +1555 -0
- package/server/index.cjs.map +1 -0
- package/server/index.d.cts +680 -0
- package/server/index.d.ts +680 -0
- package/server/index.js +1524 -0
- package/server/index.js.map +1 -0
- package/dist/analyzer-extension.d.ts +0 -105
- package/dist/analyzer-extension.d.ts.map +0 -1
- package/dist/analyzer-extension.js +0 -137
- package/dist/analyzer-extension.js.map +0 -1
- package/dist/builder/execute.d.ts +0 -26
- package/dist/builder/execute.d.ts.map +0 -1
- package/dist/builder/execute.js +0 -104
- package/dist/builder/execute.js.map +0 -1
- package/dist/builder/field-builders.d.ts +0 -30
- package/dist/builder/field-builders.d.ts.map +0 -1
- package/dist/builder/field-builders.js +0 -200
- package/dist/builder/field-builders.js.map +0 -1
- package/dist/builder/index.d.ts +0 -7
- package/dist/builder/index.d.ts.map +0 -1
- package/dist/builder/index.js +0 -31
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/pipe-api.d.ts.map +0 -1
- package/dist/builder/pipe-api.js +0 -151
- package/dist/builder/pipe-api.js.map +0 -1
- package/dist/builder/schema-builder.d.ts +0 -301
- package/dist/builder/schema-builder.d.ts.map +0 -1
- package/dist/builder/schema-builder.js +0 -566
- package/dist/builder/schema-builder.js.map +0 -1
- package/dist/builder/type-registry.d.ts +0 -80
- package/dist/builder/type-registry.d.ts.map +0 -1
- package/dist/builder/type-registry.js +0 -505
- package/dist/builder/type-registry.js.map +0 -1
- package/dist/builder/types.d.ts +0 -283
- package/dist/builder/types.d.ts.map +0 -1
- package/dist/builder/types.js +0 -3
- package/dist/builder/types.js.map +0 -1
- package/dist/cli/generate-schema.d.ts +0 -29
- package/dist/cli/generate-schema.d.ts.map +0 -1
- package/dist/cli/generate-schema.js +0 -233
- package/dist/cli/generate-schema.js.map +0 -1
- package/dist/cli/index.d.ts +0 -19
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js +0 -24
- package/dist/cli/index.js.map +0 -1
- package/dist/context.d.ts +0 -18
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -11
- package/dist/context.js.map +0 -1
- package/dist/error.d.ts +0 -45
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -29
- package/dist/error.js.map +0 -1
- package/dist/extensions.d.ts +0 -130
- package/dist/extensions.d.ts.map +0 -1
- package/dist/extensions.js +0 -78
- package/dist/extensions.js.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -47
- package/dist/index.js.map +0 -1
- package/dist/loader.d.ts +0 -169
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -237
- package/dist/loader.js.map +0 -1
- package/dist/resolver-context.d.ts +0 -154
- package/dist/resolver-context.d.ts.map +0 -1
- package/dist/resolver-context.js +0 -184
- package/dist/resolver-context.js.map +0 -1
- package/dist/schema-mapping.d.ts +0 -30
- package/dist/schema-mapping.d.ts.map +0 -1
- package/dist/schema-mapping.js +0 -280
- package/dist/schema-mapping.js.map +0 -1
- package/dist/server/cache-control.d.ts +0 -96
- package/dist/server/cache-control.d.ts.map +0 -1
- package/dist/server/cache-control.js +0 -308
- package/dist/server/cache-control.js.map +0 -1
- package/dist/server/complexity.d.ts +0 -165
- package/dist/server/complexity.d.ts.map +0 -1
- package/dist/server/complexity.js +0 -433
- package/dist/server/complexity.js.map +0 -1
- package/dist/server/config.d.ts +0 -66
- package/dist/server/config.d.ts.map +0 -1
- package/dist/server/config.js +0 -104
- package/dist/server/config.js.map +0 -1
- package/dist/server/graphiql.d.ts +0 -5
- package/dist/server/graphiql.d.ts.map +0 -1
- package/dist/server/graphiql.js +0 -43
- package/dist/server/graphiql.js.map +0 -1
- package/dist/server/index.d.ts +0 -18
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js +0 -48
- package/dist/server/index.js.map +0 -1
- package/dist/server/router.d.ts +0 -79
- package/dist/server/router.d.ts.map +0 -1
- package/dist/server/router.js +0 -232
- package/dist/server/router.js.map +0 -1
- package/dist/server/schema-builder-extensions.d.ts +0 -42
- package/dist/server/schema-builder-extensions.d.ts.map +0 -1
- package/dist/server/schema-builder-extensions.js +0 -48
- package/dist/server/schema-builder-extensions.js.map +0 -1
- package/dist/server/sse-adapter.d.ts +0 -64
- package/dist/server/sse-adapter.d.ts.map +0 -1
- package/dist/server/sse-adapter.js +0 -227
- package/dist/server/sse-adapter.js.map +0 -1
- package/dist/server/sse-types.d.ts +0 -192
- package/dist/server/sse-types.d.ts.map +0 -1
- package/dist/server/sse-types.js +0 -63
- package/dist/server/sse-types.js.map +0 -1
- package/dist/server/ws-adapter.d.ts +0 -39
- package/dist/server/ws-adapter.d.ts.map +0 -1
- package/dist/server/ws-adapter.js +0 -247
- package/dist/server/ws-adapter.js.map +0 -1
- package/dist/server/ws-types.d.ts +0 -169
- package/dist/server/ws-types.d.ts.map +0 -1
- package/dist/server/ws-types.js +0 -11
- package/dist/server/ws-types.js.map +0 -1
- package/dist/server/ws-utils.d.ts +0 -42
- package/dist/server/ws-utils.d.ts.map +0 -1
- package/dist/server/ws-utils.js +0 -99
- package/dist/server/ws-utils.js.map +0 -1
- package/src/analyzer-extension.ts +0 -254
- package/src/builder/execute.ts +0 -153
- package/src/builder/field-builders.ts +0 -322
- package/src/builder/index.ts +0 -48
- package/src/builder/pipe-api.ts +0 -312
- package/src/builder/schema-builder.ts +0 -970
- package/src/builder/type-registry.ts +0 -670
- package/src/builder/types.ts +0 -305
- package/src/context.ts +0 -23
- package/src/error.ts +0 -32
- package/src/extensions.ts +0 -240
- package/src/index.ts +0 -32
- package/src/loader.ts +0 -363
- package/src/resolver-context.ts +0 -253
- package/src/schema-mapping.ts +0 -307
- package/src/server/cache-control.ts +0 -590
- package/src/server/complexity.ts +0 -774
- package/src/server/config.ts +0 -174
- package/src/server/graphiql.ts +0 -38
- package/src/server/index.ts +0 -96
- package/src/server/router.ts +0 -432
- package/src/server/schema-builder-extensions.ts +0 -51
- package/src/server/sse-adapter.ts +0 -327
- package/src/server/sse-types.ts +0 -234
- package/src/server/ws-adapter.ts +0 -355
- package/src/server/ws-types.ts +0 -192
- package/src/server/ws-utils.ts +0 -136
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CacheControlConfigFromEnv = exports.toCacheControlHeader = exports.computeCachePolicyFromQuery = exports.computeCachePolicy = void 0;
|
|
4
|
-
const effect_1 = require("effect");
|
|
5
|
-
const graphql_1 = require("graphql");
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Cache Policy Computation
|
|
8
|
-
// ============================================================================
|
|
9
|
-
/**
|
|
10
|
-
* Compute the cache policy for a GraphQL response based on the fields resolved.
|
|
11
|
-
*
|
|
12
|
-
* The policy is computed by walking the selection set and aggregating hints:
|
|
13
|
-
* - maxAge: Use the minimum maxAge of all resolved fields
|
|
14
|
-
* - scope: If any field is PRIVATE, the entire response is PRIVATE
|
|
15
|
-
*
|
|
16
|
-
* Default behaviors (matching Apollo):
|
|
17
|
-
* - Root fields default to maxAge: 0 (unless configured otherwise)
|
|
18
|
-
* - Object-returning fields default to maxAge: 0
|
|
19
|
-
* - Scalar fields inherit their parent's maxAge
|
|
20
|
-
* - Fields with inheritMaxAge: true inherit from parent
|
|
21
|
-
*/
|
|
22
|
-
const computeCachePolicy = (info) => effect_1.Effect.sync(() => {
|
|
23
|
-
const fragments = new Map();
|
|
24
|
-
// Collect fragment definitions
|
|
25
|
-
for (const definition of info.document.definitions) {
|
|
26
|
-
if (definition.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
|
|
27
|
-
fragments.set(definition.name.value, definition);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
// Get the root type for the operation
|
|
31
|
-
const rootType = getRootType(info.schema, info.operation.operation);
|
|
32
|
-
if (!rootType) {
|
|
33
|
-
// No root type - return no-cache
|
|
34
|
-
return { maxAge: 0, scope: "PUBLIC" };
|
|
35
|
-
}
|
|
36
|
-
const defaultMaxAge = info.config.defaultMaxAge ?? 0;
|
|
37
|
-
const defaultScope = info.config.defaultScope ?? "PUBLIC";
|
|
38
|
-
// Analyze the selection set
|
|
39
|
-
const result = analyzeSelectionSet(info.operation.selectionSet, rootType, info.schema, fragments, info.cacheHints, defaultMaxAge, defaultScope, undefined, // No parent maxAge for root
|
|
40
|
-
new Set());
|
|
41
|
-
return result;
|
|
42
|
-
});
|
|
43
|
-
exports.computeCachePolicy = computeCachePolicy;
|
|
44
|
-
/**
|
|
45
|
-
* Compute cache policy from a query string
|
|
46
|
-
*/
|
|
47
|
-
const computeCachePolicyFromQuery = (query, operationName, schema, cacheHints, config = {}) => effect_1.Effect.gen(function* () {
|
|
48
|
-
// Parse the query
|
|
49
|
-
const document = yield* effect_1.Effect.try({
|
|
50
|
-
try: () => (0, graphql_1.parse)(query),
|
|
51
|
-
catch: (error) => new Error(`Failed to parse query: ${error}`),
|
|
52
|
-
});
|
|
53
|
-
// Find the operation
|
|
54
|
-
const operation = yield* effect_1.Effect.try({
|
|
55
|
-
try: () => {
|
|
56
|
-
const operations = document.definitions.filter((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
57
|
-
if (operations.length === 0) {
|
|
58
|
-
throw new Error("No operation found in query");
|
|
59
|
-
}
|
|
60
|
-
if (operationName) {
|
|
61
|
-
const op = operations.find((o) => o.name?.value === operationName);
|
|
62
|
-
if (!op) {
|
|
63
|
-
throw new Error(`Operation "${operationName}" not found`);
|
|
64
|
-
}
|
|
65
|
-
return op;
|
|
66
|
-
}
|
|
67
|
-
if (operations.length > 1) {
|
|
68
|
-
throw new Error("Multiple operations found - operationName required");
|
|
69
|
-
}
|
|
70
|
-
return operations[0];
|
|
71
|
-
},
|
|
72
|
-
catch: (error) => error,
|
|
73
|
-
});
|
|
74
|
-
return yield* (0, exports.computeCachePolicy)({
|
|
75
|
-
document,
|
|
76
|
-
operation,
|
|
77
|
-
schema,
|
|
78
|
-
cacheHints,
|
|
79
|
-
config,
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
exports.computeCachePolicyFromQuery = computeCachePolicyFromQuery;
|
|
83
|
-
/**
|
|
84
|
-
* Convert a cache policy to an HTTP Cache-Control header value
|
|
85
|
-
*/
|
|
86
|
-
const toCacheControlHeader = (policy) => {
|
|
87
|
-
if (policy.maxAge === 0) {
|
|
88
|
-
return "no-store";
|
|
89
|
-
}
|
|
90
|
-
const directives = [];
|
|
91
|
-
directives.push(policy.scope === "PRIVATE" ? "private" : "public");
|
|
92
|
-
directives.push(`max-age=${policy.maxAge}`);
|
|
93
|
-
return directives.join(", ");
|
|
94
|
-
};
|
|
95
|
-
exports.toCacheControlHeader = toCacheControlHeader;
|
|
96
|
-
// ============================================================================
|
|
97
|
-
// Internal Helpers
|
|
98
|
-
// ============================================================================
|
|
99
|
-
/**
|
|
100
|
-
* Get the root type for an operation
|
|
101
|
-
*/
|
|
102
|
-
function getRootType(schema, operation) {
|
|
103
|
-
switch (operation) {
|
|
104
|
-
case "query":
|
|
105
|
-
return schema.getQueryType() ?? null;
|
|
106
|
-
case "mutation":
|
|
107
|
-
return schema.getMutationType() ?? null;
|
|
108
|
-
case "subscription":
|
|
109
|
-
return schema.getSubscriptionType() ?? null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the named type from a potentially wrapped type
|
|
114
|
-
*/
|
|
115
|
-
function getNamedType(type) {
|
|
116
|
-
if (type instanceof graphql_1.GraphQLNonNull || type instanceof graphql_1.GraphQLList) {
|
|
117
|
-
return getNamedType(type.ofType);
|
|
118
|
-
}
|
|
119
|
-
if (type instanceof graphql_1.GraphQLObjectType ||
|
|
120
|
-
type instanceof graphql_1.GraphQLScalarType ||
|
|
121
|
-
type instanceof graphql_1.GraphQLEnumType) {
|
|
122
|
-
return type;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Check if a type is a scalar or enum (leaf type)
|
|
128
|
-
*/
|
|
129
|
-
function isLeafType(type) {
|
|
130
|
-
const namedType = getNamedType(type);
|
|
131
|
-
return namedType instanceof graphql_1.GraphQLScalarType || namedType instanceof graphql_1.GraphQLEnumType;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Aggregate a field policy into the accumulator
|
|
135
|
-
*/
|
|
136
|
-
function aggregatePolicy(acc, policy) {
|
|
137
|
-
if (acc.minMaxAge === undefined) {
|
|
138
|
-
acc.minMaxAge = policy.maxAge;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
acc.minMaxAge = Math.min(acc.minMaxAge, policy.maxAge);
|
|
142
|
-
}
|
|
143
|
-
if (policy.scope === "PRIVATE") {
|
|
144
|
-
acc.hasPrivate = true;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Analyze a fragment spread and return its cache policy
|
|
149
|
-
*/
|
|
150
|
-
function analyzeFragmentSpread(fragmentName, ctx, parentMaxAge, visitedFragments) {
|
|
151
|
-
// Prevent infinite loops with fragment cycles
|
|
152
|
-
if (visitedFragments.has(fragmentName)) {
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
const fragment = ctx.fragments.get(fragmentName);
|
|
156
|
-
if (!fragment) {
|
|
157
|
-
return undefined;
|
|
158
|
-
}
|
|
159
|
-
const fragmentType = ctx.schema.getType(fragment.typeCondition.name.value);
|
|
160
|
-
if (!(fragmentType instanceof graphql_1.GraphQLObjectType)) {
|
|
161
|
-
return undefined;
|
|
162
|
-
}
|
|
163
|
-
const newVisited = new Set(visitedFragments);
|
|
164
|
-
newVisited.add(fragmentName);
|
|
165
|
-
return analyzeSelectionSet(fragment.selectionSet, fragmentType, ctx, parentMaxAge, newVisited);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Analyze an inline fragment and return its cache policy
|
|
169
|
-
*/
|
|
170
|
-
function analyzeInlineFragment(selection, parentType, ctx, parentMaxAge, visitedFragments) {
|
|
171
|
-
let targetType = parentType;
|
|
172
|
-
if (selection.typeCondition) {
|
|
173
|
-
const conditionType = ctx.schema.getType(selection.typeCondition.name.value);
|
|
174
|
-
if (conditionType instanceof graphql_1.GraphQLObjectType) {
|
|
175
|
-
targetType = conditionType;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return analyzeSelectionSet(selection.selectionSet, targetType, ctx, parentMaxAge, visitedFragments);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Look up the effective cache hint for a field (field-level > type-level > undefined)
|
|
182
|
-
*/
|
|
183
|
-
function lookupEffectiveCacheHint(parentTypeName, fieldName, returnType, cacheHints) {
|
|
184
|
-
// Priority: field-level hint > type-level hint
|
|
185
|
-
const fieldKey = `${parentTypeName}.${fieldName}`;
|
|
186
|
-
const fieldHint = cacheHints.get(fieldKey);
|
|
187
|
-
if (fieldHint)
|
|
188
|
-
return fieldHint;
|
|
189
|
-
// Check type-level hint on return type
|
|
190
|
-
const namedType = getNamedType(returnType);
|
|
191
|
-
return namedType ? cacheHints.get(namedType.name) : undefined;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Compute the maxAge for a field based on hint, inheritance, and field type
|
|
195
|
-
*/
|
|
196
|
-
function computeFieldMaxAge(hint, fieldType, parentMaxAge, defaultMaxAge) {
|
|
197
|
-
if (hint) {
|
|
198
|
-
// Use explicit hint
|
|
199
|
-
if (hint.inheritMaxAge && parentMaxAge !== undefined) {
|
|
200
|
-
return parentMaxAge;
|
|
201
|
-
}
|
|
202
|
-
if (hint.maxAge !== undefined) {
|
|
203
|
-
return hint.maxAge;
|
|
204
|
-
}
|
|
205
|
-
// Fall through to default logic
|
|
206
|
-
}
|
|
207
|
-
// Scalar/enum fields inherit parent maxAge by default
|
|
208
|
-
if (isLeafType(fieldType) && parentMaxAge !== undefined) {
|
|
209
|
-
return parentMaxAge;
|
|
210
|
-
}
|
|
211
|
-
// Root and object fields default to defaultMaxAge (typically 0)
|
|
212
|
-
return defaultMaxAge;
|
|
213
|
-
}
|
|
214
|
-
function analyzeSelectionSet(selectionSet, parentType, schemaOrCtx, fragmentsOrParentMaxAge, cacheHintsOrVisited, defaultMaxAge, defaultScope, parentMaxAge, visitedFragments) {
|
|
215
|
-
// Normalize arguments - support both old and new signatures
|
|
216
|
-
let ctx;
|
|
217
|
-
let actualParentMaxAge;
|
|
218
|
-
let actualVisitedFragments;
|
|
219
|
-
if (schemaOrCtx instanceof graphql_1.GraphQLSchema) {
|
|
220
|
-
// Old signature
|
|
221
|
-
ctx = {
|
|
222
|
-
schema: schemaOrCtx,
|
|
223
|
-
fragments: fragmentsOrParentMaxAge,
|
|
224
|
-
cacheHints: cacheHintsOrVisited,
|
|
225
|
-
defaultMaxAge: defaultMaxAge,
|
|
226
|
-
defaultScope: defaultScope,
|
|
227
|
-
};
|
|
228
|
-
actualParentMaxAge = parentMaxAge;
|
|
229
|
-
actualVisitedFragments = visitedFragments;
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
// New signature with AnalysisContext
|
|
233
|
-
ctx = schemaOrCtx;
|
|
234
|
-
actualParentMaxAge = fragmentsOrParentMaxAge;
|
|
235
|
-
actualVisitedFragments = cacheHintsOrVisited;
|
|
236
|
-
}
|
|
237
|
-
const acc = { minMaxAge: undefined, hasPrivate: false };
|
|
238
|
-
for (const selection of selectionSet.selections) {
|
|
239
|
-
let fieldPolicy;
|
|
240
|
-
switch (selection.kind) {
|
|
241
|
-
case graphql_1.Kind.FIELD:
|
|
242
|
-
fieldPolicy = analyzeField(selection, parentType, ctx, actualParentMaxAge, actualVisitedFragments);
|
|
243
|
-
break;
|
|
244
|
-
case graphql_1.Kind.FRAGMENT_SPREAD:
|
|
245
|
-
fieldPolicy = analyzeFragmentSpread(selection.name.value, ctx, actualParentMaxAge, actualVisitedFragments);
|
|
246
|
-
break;
|
|
247
|
-
case graphql_1.Kind.INLINE_FRAGMENT:
|
|
248
|
-
fieldPolicy = analyzeInlineFragment(selection, parentType, ctx, actualParentMaxAge, actualVisitedFragments);
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
if (fieldPolicy) {
|
|
252
|
-
aggregatePolicy(acc, fieldPolicy);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
return {
|
|
256
|
-
maxAge: acc.minMaxAge ?? ctx.defaultMaxAge,
|
|
257
|
-
scope: acc.hasPrivate ? "PRIVATE" : ctx.defaultScope,
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Analyze a field node and return its cache policy
|
|
262
|
-
*/
|
|
263
|
-
function analyzeField(field, parentType, ctx, parentMaxAge, visitedFragments) {
|
|
264
|
-
const fieldName = field.name.value;
|
|
265
|
-
// Introspection fields - don't affect caching
|
|
266
|
-
if (fieldName.startsWith("__")) {
|
|
267
|
-
return { maxAge: Infinity, scope: "PUBLIC" };
|
|
268
|
-
}
|
|
269
|
-
// Get the field from the schema
|
|
270
|
-
const schemaField = parentType.getFields()[fieldName];
|
|
271
|
-
if (!schemaField) {
|
|
272
|
-
return { maxAge: ctx.defaultMaxAge, scope: ctx.defaultScope };
|
|
273
|
-
}
|
|
274
|
-
// Look up effective cache hint
|
|
275
|
-
const effectiveHint = lookupEffectiveCacheHint(parentType.name, fieldName, schemaField.type, ctx.cacheHints);
|
|
276
|
-
// Compute field maxAge
|
|
277
|
-
const fieldMaxAge = computeFieldMaxAge(effectiveHint, schemaField.type, parentMaxAge, ctx.defaultMaxAge);
|
|
278
|
-
const fieldScope = effectiveHint?.scope ?? ctx.defaultScope;
|
|
279
|
-
// If the field has a selection set, analyze it
|
|
280
|
-
const namedType = getNamedType(schemaField.type);
|
|
281
|
-
if (field.selectionSet && namedType instanceof graphql_1.GraphQLObjectType) {
|
|
282
|
-
const nestedPolicy = analyzeSelectionSet(field.selectionSet, namedType, ctx, fieldMaxAge, visitedFragments);
|
|
283
|
-
return {
|
|
284
|
-
maxAge: Math.min(fieldMaxAge, nestedPolicy.maxAge),
|
|
285
|
-
scope: fieldScope === "PRIVATE" || nestedPolicy.scope === "PRIVATE" ? "PRIVATE" : "PUBLIC",
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
return { maxAge: fieldMaxAge, scope: fieldScope };
|
|
289
|
-
}
|
|
290
|
-
// ============================================================================
|
|
291
|
-
// Environment Configuration
|
|
292
|
-
// ============================================================================
|
|
293
|
-
/**
|
|
294
|
-
* Effect Config for loading cache control configuration from environment variables.
|
|
295
|
-
*
|
|
296
|
-
* Environment variables:
|
|
297
|
-
* - GRAPHQL_CACHE_CONTROL_ENABLED: Enable cache control (default: true)
|
|
298
|
-
* - GRAPHQL_CACHE_CONTROL_DEFAULT_MAX_AGE: Default maxAge for root fields (default: 0)
|
|
299
|
-
* - GRAPHQL_CACHE_CONTROL_DEFAULT_SCOPE: Default scope (PUBLIC or PRIVATE, default: PUBLIC)
|
|
300
|
-
* - GRAPHQL_CACHE_CONTROL_HTTP_HEADERS: Set HTTP headers (default: true)
|
|
301
|
-
*/
|
|
302
|
-
exports.CacheControlConfigFromEnv = effect_1.Config.all({
|
|
303
|
-
enabled: effect_1.Config.boolean("GRAPHQL_CACHE_CONTROL_ENABLED").pipe(effect_1.Config.withDefault(true)),
|
|
304
|
-
defaultMaxAge: effect_1.Config.number("GRAPHQL_CACHE_CONTROL_DEFAULT_MAX_AGE").pipe(effect_1.Config.withDefault(0)),
|
|
305
|
-
defaultScope: effect_1.Config.string("GRAPHQL_CACHE_CONTROL_DEFAULT_SCOPE").pipe(effect_1.Config.withDefault("PUBLIC"), effect_1.Config.map((s) => (s === "PRIVATE" ? "PRIVATE" : "PUBLIC"))),
|
|
306
|
-
calculateHttpHeaders: effect_1.Config.boolean("GRAPHQL_CACHE_CONTROL_HTTP_HEADERS").pipe(effect_1.Config.withDefault(true)),
|
|
307
|
-
});
|
|
308
|
-
//# sourceMappingURL=cache-control.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cache-control.js","sourceRoot":"","sources":["../../src/server/cache-control.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AACvC,qCAegB;AA2EhB,+EAA+E;AAC/E,2BAA2B;AAC3B,+EAA+E;AAE/E;;;;;;;;;;;;GAYG;AACI,MAAM,kBAAkB,GAAG,CAChC,IAA6B,EACa,EAAE,CAC5C,eAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IACf,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkC,CAAA;IAE3D,+BAA+B;IAC/B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,UAAU,CAAC,IAAI,KAAK,cAAI,CAAC,mBAAmB,EAAE,CAAC;YACjD,SAAS,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;QAClD,CAAC;IACH,CAAC;IAED,sCAAsC;IACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;IACnE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,iCAAiC;QACjC,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,QAAiB,EAAE,CAAA;I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;IACD,oBAAoB,EAAE,eAAM,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC,IAAI,CAC7E,eAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CACzB;CACF,CAAC,CAAA"}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { Effect, Config } from "effect";
|
|
2
|
-
import { DocumentNode, OperationDefinitionNode, GraphQLSchema } from "graphql";
|
|
3
|
-
declare const ComplexityLimitExceededError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
4
|
-
readonly _tag: "ComplexityLimitExceededError";
|
|
5
|
-
} & Readonly<A>;
|
|
6
|
-
/**
|
|
7
|
-
* Error thrown when query complexity exceeds configured limits
|
|
8
|
-
*/
|
|
9
|
-
export declare class ComplexityLimitExceededError extends ComplexityLimitExceededError_base<{
|
|
10
|
-
readonly message: string;
|
|
11
|
-
readonly limit: number;
|
|
12
|
-
readonly actual: number;
|
|
13
|
-
readonly limitType: "depth" | "complexity" | "aliases" | "fields";
|
|
14
|
-
}> {
|
|
15
|
-
}
|
|
16
|
-
declare const ComplexityAnalysisError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
17
|
-
readonly _tag: "ComplexityAnalysisError";
|
|
18
|
-
} & Readonly<A>;
|
|
19
|
-
/**
|
|
20
|
-
* Error thrown when complexity analysis fails
|
|
21
|
-
*/
|
|
22
|
-
export declare class ComplexityAnalysisError extends ComplexityAnalysisError_base<{
|
|
23
|
-
readonly message: string;
|
|
24
|
-
readonly cause?: unknown;
|
|
25
|
-
}> {
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Result of complexity analysis for a GraphQL operation
|
|
29
|
-
*/
|
|
30
|
-
export interface ComplexityResult {
|
|
31
|
-
/** Maximum depth of the query */
|
|
32
|
-
readonly depth: number;
|
|
33
|
-
/** Total complexity score */
|
|
34
|
-
readonly complexity: number;
|
|
35
|
-
/** Number of field selections (including nested) */
|
|
36
|
-
readonly fieldCount: number;
|
|
37
|
-
/** Number of aliased fields */
|
|
38
|
-
readonly aliasCount: number;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Information provided to complexity calculators
|
|
42
|
-
*/
|
|
43
|
-
export interface ComplexityAnalysisInfo {
|
|
44
|
-
/** Parsed GraphQL document */
|
|
45
|
-
readonly document: DocumentNode;
|
|
46
|
-
/** The operation being executed */
|
|
47
|
-
readonly operation: OperationDefinitionNode;
|
|
48
|
-
/** Variables provided with the query */
|
|
49
|
-
readonly variables?: Record<string, unknown>;
|
|
50
|
-
/** The GraphQL schema */
|
|
51
|
-
readonly schema: GraphQLSchema;
|
|
52
|
-
/** Field complexity definitions from the builder */
|
|
53
|
-
readonly fieldComplexities: FieldComplexityMap;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Information provided when complexity limit is exceeded
|
|
57
|
-
*/
|
|
58
|
-
export interface ComplexityExceededInfo {
|
|
59
|
-
/** The computed complexity result */
|
|
60
|
-
readonly result: ComplexityResult;
|
|
61
|
-
/** Which limit was exceeded */
|
|
62
|
-
readonly exceededLimit: "depth" | "complexity" | "aliases" | "fields";
|
|
63
|
-
/** The limit value */
|
|
64
|
-
readonly limit: number;
|
|
65
|
-
/** The actual value */
|
|
66
|
-
readonly actual: number;
|
|
67
|
-
/** The query that exceeded limits */
|
|
68
|
-
readonly query: string;
|
|
69
|
-
/** Operation name if provided */
|
|
70
|
-
readonly operationName?: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Complexity value for a field - can be static or dynamic based on arguments
|
|
74
|
-
*/
|
|
75
|
-
export type FieldComplexity = number | ((args: Record<string, unknown>) => number);
|
|
76
|
-
/**
|
|
77
|
-
* Map of type.field -> complexity
|
|
78
|
-
*/
|
|
79
|
-
export type FieldComplexityMap = Map<string, FieldComplexity>;
|
|
80
|
-
/**
|
|
81
|
-
* Custom complexity calculator function.
|
|
82
|
-
* Must be self-contained (no service requirements).
|
|
83
|
-
*/
|
|
84
|
-
export type ComplexityCalculator = (info: ComplexityAnalysisInfo) => Effect.Effect<ComplexityResult, ComplexityAnalysisError, never>;
|
|
85
|
-
/**
|
|
86
|
-
* Configuration for query complexity limiting
|
|
87
|
-
*/
|
|
88
|
-
export interface ComplexityConfig {
|
|
89
|
-
/**
|
|
90
|
-
* Maximum allowed query depth.
|
|
91
|
-
* Depth is the deepest nesting level in the query.
|
|
92
|
-
* @example
|
|
93
|
-
* // Depth 3:
|
|
94
|
-
* // { user { posts { comments { text } } } }
|
|
95
|
-
*/
|
|
96
|
-
readonly maxDepth?: number;
|
|
97
|
-
/**
|
|
98
|
-
* Maximum allowed total complexity score.
|
|
99
|
-
* Complexity is calculated by summing field costs.
|
|
100
|
-
*/
|
|
101
|
-
readonly maxComplexity?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Maximum number of field aliases allowed.
|
|
104
|
-
* Prevents response explosion attacks via aliases.
|
|
105
|
-
*/
|
|
106
|
-
readonly maxAliases?: number;
|
|
107
|
-
/**
|
|
108
|
-
* Maximum total number of fields in the query.
|
|
109
|
-
* Includes all nested field selections.
|
|
110
|
-
*/
|
|
111
|
-
readonly maxFields?: number;
|
|
112
|
-
/**
|
|
113
|
-
* Default complexity cost for fields without explicit costs.
|
|
114
|
-
* @default 1
|
|
115
|
-
*/
|
|
116
|
-
readonly defaultFieldComplexity?: number;
|
|
117
|
-
/**
|
|
118
|
-
* Custom complexity calculator.
|
|
119
|
-
* If provided, this is used instead of the default calculator.
|
|
120
|
-
* Can be used to implement custom cost algorithms.
|
|
121
|
-
*/
|
|
122
|
-
readonly calculator?: ComplexityCalculator;
|
|
123
|
-
/**
|
|
124
|
-
* Hook called when a limit is exceeded.
|
|
125
|
-
* Useful for logging, metrics, or custom handling.
|
|
126
|
-
* This is called BEFORE the error is thrown.
|
|
127
|
-
* Must be self-contained (no service requirements).
|
|
128
|
-
*/
|
|
129
|
-
readonly onExceeded?: (info: ComplexityExceededInfo) => Effect.Effect<void, never, never>;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Default complexity calculator that walks the AST and computes:
|
|
133
|
-
* - depth: Maximum nesting level
|
|
134
|
-
* - complexity: Sum of field costs
|
|
135
|
-
* - fieldCount: Total number of field selections
|
|
136
|
-
* - aliasCount: Number of aliased fields
|
|
137
|
-
*/
|
|
138
|
-
export declare const defaultComplexityCalculator: (defaultCost?: number) => ComplexityCalculator;
|
|
139
|
-
/**
|
|
140
|
-
* Validate query complexity against configured limits.
|
|
141
|
-
* Returns the complexity result if within limits, or fails with ComplexityLimitExceededError.
|
|
142
|
-
*/
|
|
143
|
-
export declare const validateComplexity: (query: string, operationName: string | undefined, variables: Record<string, unknown> | undefined, schema: GraphQLSchema, fieldComplexities: FieldComplexityMap, config: ComplexityConfig) => Effect.Effect<ComplexityResult, ComplexityLimitExceededError | ComplexityAnalysisError, never>;
|
|
144
|
-
/**
|
|
145
|
-
* Effect Config for loading complexity configuration from environment variables.
|
|
146
|
-
*
|
|
147
|
-
* Environment variables:
|
|
148
|
-
* - GRAPHQL_MAX_DEPTH: Maximum query depth
|
|
149
|
-
* - GRAPHQL_MAX_COMPLEXITY: Maximum complexity score
|
|
150
|
-
* - GRAPHQL_MAX_ALIASES: Maximum number of aliases
|
|
151
|
-
* - GRAPHQL_MAX_FIELDS: Maximum number of fields
|
|
152
|
-
* - GRAPHQL_DEFAULT_FIELD_COMPLEXITY: Default field complexity (default: 1)
|
|
153
|
-
*/
|
|
154
|
-
export declare const ComplexityConfigFromEnv: Config.Config<ComplexityConfig>;
|
|
155
|
-
/**
|
|
156
|
-
* A simple depth-only calculator that only tracks query depth.
|
|
157
|
-
* Use this when you only care about depth limiting and want fast validation.
|
|
158
|
-
*/
|
|
159
|
-
export declare const depthOnlyCalculator: ComplexityCalculator;
|
|
160
|
-
/**
|
|
161
|
-
* Combine multiple calculators - returns the maximum values from all calculators.
|
|
162
|
-
*/
|
|
163
|
-
export declare const combineCalculators: (...calculators: ComplexityCalculator[]) => ComplexityCalculator;
|
|
164
|
-
export {};
|
|
165
|
-
//# sourceMappingURL=complexity.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/server/complexity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,EAAQ,MAAM,QAAQ,CAAA;AACrD,OAAO,EACL,YAAY,EACZ,uBAAuB,EAMvB,aAAa,EAOd,MAAM,SAAS,CAAA;;;;AAMhB;;GAEG;AACH,qBAAa,4BAA6B,SAAQ,kCAAiD;IACjG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,CAAA;CAClE,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,6BAA4C;IACvF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC;CAAG;AAML;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,6BAA6B;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,8BAA8B;IAC9B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