@effect-gql/core 1.0.0 → 1.1.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/builder/index.cjs +17 -2
- package/builder/index.cjs.map +1 -1
- package/builder/index.d.cts +3 -2
- package/builder/index.d.ts +3 -2
- package/builder/index.js +17 -2
- package/builder/index.js.map +1 -1
- package/index.cjs +107 -57
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -3
- package/index.d.ts +9 -3
- package/index.js +109 -59
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/{schema-builder-Cvdq7Kz_.d.cts → schema-builder-DKvkzU_M.d.cts} +2 -0
- package/{schema-builder-Cvdq7Kz_.d.ts → schema-builder-DKvkzU_M.d.ts} +2 -0
- package/server/index.cjs +54 -30
- package/server/index.cjs.map +1 -1
- package/server/index.d.cts +5 -3
- package/server/index.d.ts +5 -3
- package/server/index.js +56 -32
- package/server/index.js.map +1 -1
package/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FieldComplexityMap, G as GraphQLExtension, E as ExtensionsService } from './schema-builder-
|
|
2
|
-
export { y as CacheControlConfig, J as CacheControlConfigFromEnv, h as CacheControlScope, C as CacheHint, w as CacheHintMap, x as CachePolicy, z as CachePolicyAnalysisInfo, q as ComplexityAnalysisError, l as ComplexityAnalysisInfo, n as ComplexityCalculator, j as ComplexityConfig, u as ComplexityConfigFromEnv, m as ComplexityExceededInfo, p as ComplexityLimitExceededError, k as ComplexityResult, D as DirectiveApplication, d as DirectiveRegistration, b as EnumRegistration, K as ExecutionArgs, o as FieldComplexity, a as FieldRegistration, f as GraphQLEffectContext, i as GraphQLSchemaBuilder, c as InputTypeRegistration, I as InterfaceRegistration, M as MiddlewareContext, e as MiddlewareRegistration, O as ObjectFieldRegistration, S as SubscriptionFieldRegistration, T as TypeRegistration, g as TypeRegistries, U as UnionRegistration, t as combineCalculators, A as computeCachePolicy, B as computeCachePolicyFromQuery, r as defaultComplexityCalculator, s as depthOnlyCalculator, L as makeExtensionsService, R as runExecuteEndHooks, Q as runExecuteStartHooks, N as runParseHooks, P as runValidateHooks, H as toCacheControlHeader, v as validateComplexity } from './schema-builder-
|
|
1
|
+
import { F as FieldComplexityMap, G as GraphQLExtension, E as ExtensionsService } from './schema-builder-DKvkzU_M.cjs';
|
|
2
|
+
export { y as CacheControlConfig, J as CacheControlConfigFromEnv, h as CacheControlScope, C as CacheHint, w as CacheHintMap, x as CachePolicy, z as CachePolicyAnalysisInfo, q as ComplexityAnalysisError, l as ComplexityAnalysisInfo, n as ComplexityCalculator, j as ComplexityConfig, u as ComplexityConfigFromEnv, m as ComplexityExceededInfo, p as ComplexityLimitExceededError, k as ComplexityResult, D as DirectiveApplication, d as DirectiveRegistration, b as EnumRegistration, K as ExecutionArgs, o as FieldComplexity, a as FieldRegistration, f as GraphQLEffectContext, i as GraphQLSchemaBuilder, c as InputTypeRegistration, I as InterfaceRegistration, M as MiddlewareContext, e as MiddlewareRegistration, O as ObjectFieldRegistration, S as SubscriptionFieldRegistration, T as TypeRegistration, g as TypeRegistries, U as UnionRegistration, t as combineCalculators, A as computeCachePolicy, B as computeCachePolicyFromQuery, r as defaultComplexityCalculator, s as depthOnlyCalculator, L as makeExtensionsService, R as runExecuteEndHooks, Q as runExecuteStartHooks, N as runParseHooks, P as runValidateHooks, H as toCacheControlHeader, v as validateComplexity } from './schema-builder-DKvkzU_M.cjs';
|
|
3
3
|
import { GraphQLOutputType, GraphQLInputType, GraphQLFieldConfigArgumentMap, GraphQLObjectType } from 'graphql';
|
|
4
4
|
export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfigMap, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, ValueNode, graphql, lexicographicSortSchema, printSchema } from 'graphql';
|
|
5
5
|
export { compose, directive, enumType, execute, extension, field, getSchemaName, inputType, interfaceType, middleware, mutation, objectType, query, subscription, unionType } from './builder/index.cjs';
|
|
@@ -216,11 +216,17 @@ declare class LoaderRegistry<Defs extends Record<string, LoaderDef<any, any, any
|
|
|
216
216
|
/**
|
|
217
217
|
* Load a single value by key.
|
|
218
218
|
* This is the most common operation in resolvers.
|
|
219
|
+
*
|
|
220
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
221
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
219
222
|
*/
|
|
220
223
|
load<Name extends keyof Defs & string>(name: Name, key: LoaderKey<Defs[Name]>): Effect.Effect<LoaderValue<Defs[Name]>, Error, LoaderInstances<Defs>>;
|
|
221
224
|
/**
|
|
222
225
|
* Load multiple values by keys.
|
|
223
226
|
* All keys are batched into a single request.
|
|
227
|
+
*
|
|
228
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
229
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
224
230
|
*/
|
|
225
231
|
loadMany<Name extends keyof Defs & string>(name: Name, keys: readonly LoaderKey<Defs[Name]>[]): Effect.Effect<readonly LoaderValue<Defs[Name]>[], Error, LoaderInstances<Defs>>;
|
|
226
232
|
}
|
|
@@ -520,4 +526,4 @@ interface AnalyzerOutput {
|
|
|
520
526
|
*/
|
|
521
527
|
declare const createAnalyzerExtension: (config?: AnalyzerExtensionConfig) => GraphQLExtension<ExtensionsService>;
|
|
522
528
|
|
|
523
|
-
export { type AdditionalField, type AnalyzerExtensionConfig, type AnalyzerOutput, AuthorizationError, ExtensionsService, FieldComplexityMap, GraphQLError, GraphQLExtension, GraphQLRequestContext, Loader, type LoaderDef, type LoaderInstances, LoaderRegistry, MissingResolverContextError, NotFoundError, ResolverContext, type ResolverContextSlot, ResolverContextStore, ValidationError, createAnalyzerExtension, get, getOption, getOrElse, has, make, makeRequestContextLayer, makeStoreLayer, scoped, set, setMany, storeLayer, toGraphQLArgs, toGraphQLInputType, toGraphQLObjectType, toGraphQLType };
|
|
529
|
+
export { type AdditionalField, type AnalyzerExtensionConfig, type AnalyzerOutput, AuthorizationError, ExtensionsService, FieldComplexityMap, GraphQLError, GraphQLExtension, GraphQLRequestContext, type GroupedLoaderDef, Loader, type LoaderDef, type LoaderInstances, LoaderRegistry, MissingResolverContextError, NotFoundError, ResolverContext, type ResolverContextSlot, ResolverContextStore, type SingleLoaderDef, ValidationError, createAnalyzerExtension, get, getOption, getOrElse, has, make, makeRequestContextLayer, makeStoreLayer, scoped, set, setMany, storeLayer, toGraphQLArgs, toGraphQLInputType, toGraphQLObjectType, toGraphQLType };
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FieldComplexityMap, G as GraphQLExtension, E as ExtensionsService } from './schema-builder-
|
|
2
|
-
export { y as CacheControlConfig, J as CacheControlConfigFromEnv, h as CacheControlScope, C as CacheHint, w as CacheHintMap, x as CachePolicy, z as CachePolicyAnalysisInfo, q as ComplexityAnalysisError, l as ComplexityAnalysisInfo, n as ComplexityCalculator, j as ComplexityConfig, u as ComplexityConfigFromEnv, m as ComplexityExceededInfo, p as ComplexityLimitExceededError, k as ComplexityResult, D as DirectiveApplication, d as DirectiveRegistration, b as EnumRegistration, K as ExecutionArgs, o as FieldComplexity, a as FieldRegistration, f as GraphQLEffectContext, i as GraphQLSchemaBuilder, c as InputTypeRegistration, I as InterfaceRegistration, M as MiddlewareContext, e as MiddlewareRegistration, O as ObjectFieldRegistration, S as SubscriptionFieldRegistration, T as TypeRegistration, g as TypeRegistries, U as UnionRegistration, t as combineCalculators, A as computeCachePolicy, B as computeCachePolicyFromQuery, r as defaultComplexityCalculator, s as depthOnlyCalculator, L as makeExtensionsService, R as runExecuteEndHooks, Q as runExecuteStartHooks, N as runParseHooks, P as runValidateHooks, H as toCacheControlHeader, v as validateComplexity } from './schema-builder-
|
|
1
|
+
import { F as FieldComplexityMap, G as GraphQLExtension, E as ExtensionsService } from './schema-builder-DKvkzU_M.js';
|
|
2
|
+
export { y as CacheControlConfig, J as CacheControlConfigFromEnv, h as CacheControlScope, C as CacheHint, w as CacheHintMap, x as CachePolicy, z as CachePolicyAnalysisInfo, q as ComplexityAnalysisError, l as ComplexityAnalysisInfo, n as ComplexityCalculator, j as ComplexityConfig, u as ComplexityConfigFromEnv, m as ComplexityExceededInfo, p as ComplexityLimitExceededError, k as ComplexityResult, D as DirectiveApplication, d as DirectiveRegistration, b as EnumRegistration, K as ExecutionArgs, o as FieldComplexity, a as FieldRegistration, f as GraphQLEffectContext, i as GraphQLSchemaBuilder, c as InputTypeRegistration, I as InterfaceRegistration, M as MiddlewareContext, e as MiddlewareRegistration, O as ObjectFieldRegistration, S as SubscriptionFieldRegistration, T as TypeRegistration, g as TypeRegistries, U as UnionRegistration, t as combineCalculators, A as computeCachePolicy, B as computeCachePolicyFromQuery, r as defaultComplexityCalculator, s as depthOnlyCalculator, L as makeExtensionsService, R as runExecuteEndHooks, Q as runExecuteStartHooks, N as runParseHooks, P as runValidateHooks, H as toCacheControlHeader, v as validateComplexity } from './schema-builder-DKvkzU_M.js';
|
|
3
3
|
import { GraphQLOutputType, GraphQLInputType, GraphQLFieldConfigArgumentMap, GraphQLObjectType } from 'graphql';
|
|
4
4
|
export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfigMap, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, ValueNode, graphql, lexicographicSortSchema, printSchema } from 'graphql';
|
|
5
5
|
export { compose, directive, enumType, execute, extension, field, getSchemaName, inputType, interfaceType, middleware, mutation, objectType, query, subscription, unionType } from './builder/index.js';
|
|
@@ -216,11 +216,17 @@ declare class LoaderRegistry<Defs extends Record<string, LoaderDef<any, any, any
|
|
|
216
216
|
/**
|
|
217
217
|
* Load a single value by key.
|
|
218
218
|
* This is the most common operation in resolvers.
|
|
219
|
+
*
|
|
220
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
221
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
219
222
|
*/
|
|
220
223
|
load<Name extends keyof Defs & string>(name: Name, key: LoaderKey<Defs[Name]>): Effect.Effect<LoaderValue<Defs[Name]>, Error, LoaderInstances<Defs>>;
|
|
221
224
|
/**
|
|
222
225
|
* Load multiple values by keys.
|
|
223
226
|
* All keys are batched into a single request.
|
|
227
|
+
*
|
|
228
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
229
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
224
230
|
*/
|
|
225
231
|
loadMany<Name extends keyof Defs & string>(name: Name, keys: readonly LoaderKey<Defs[Name]>[]): Effect.Effect<readonly LoaderValue<Defs[Name]>[], Error, LoaderInstances<Defs>>;
|
|
226
232
|
}
|
|
@@ -520,4 +526,4 @@ interface AnalyzerOutput {
|
|
|
520
526
|
*/
|
|
521
527
|
declare const createAnalyzerExtension: (config?: AnalyzerExtensionConfig) => GraphQLExtension<ExtensionsService>;
|
|
522
528
|
|
|
523
|
-
export { type AdditionalField, type AnalyzerExtensionConfig, type AnalyzerOutput, AuthorizationError, ExtensionsService, FieldComplexityMap, GraphQLError, GraphQLExtension, GraphQLRequestContext, Loader, type LoaderDef, type LoaderInstances, LoaderRegistry, MissingResolverContextError, NotFoundError, ResolverContext, type ResolverContextSlot, ResolverContextStore, ValidationError, createAnalyzerExtension, get, getOption, getOrElse, has, make, makeRequestContextLayer, makeStoreLayer, scoped, set, setMany, storeLayer, toGraphQLArgs, toGraphQLInputType, toGraphQLObjectType, toGraphQLType };
|
|
529
|
+
export { type AdditionalField, type AnalyzerExtensionConfig, type AnalyzerOutput, AuthorizationError, ExtensionsService, FieldComplexityMap, GraphQLError, GraphQLExtension, GraphQLRequestContext, type GroupedLoaderDef, Loader, type LoaderDef, type LoaderInstances, LoaderRegistry, MissingResolverContextError, NotFoundError, ResolverContext, type ResolverContextSlot, ResolverContextStore, type SingleLoaderDef, ValidationError, createAnalyzerExtension, get, getOption, getOrElse, has, make, makeRequestContextLayer, makeStoreLayer, scoped, set, setMany, storeLayer, toGraphQLArgs, toGraphQLInputType, toGraphQLObjectType, toGraphQLType };
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, GraphQLSchema, GraphQLNonNull, GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLInt, GraphQLList, parse, GraphQLError, validate, execute as execute$1, Kind, specifiedRules, NoSchemaIntrospectionCustomRule, subscribe, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, graphql, lexicographicSortSchema, printSchema } from 'graphql';
|
|
3
|
-
import { Pipeable, Context, Data, Layer, Effect, Ref, HashMap, Config, Option, Runtime, Queue, Stream, Fiber, Deferred } from 'effect';
|
|
3
|
+
import { Pipeable, Context, Data, Layer, Effect, Ref, HashMap, Config, Option, Schema, Runtime, Queue, Stream, Fiber, Deferred } from 'effect';
|
|
4
4
|
import * as S2 from 'effect/Schema';
|
|
5
5
|
import * as AST from 'effect/SchemaAST';
|
|
6
6
|
import DataLoader from 'dataloader';
|
|
7
|
-
import { HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
|
|
7
|
+
import { HttpIncomingMessage, HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
|
|
8
8
|
import { makeServer } from 'graphql-ws';
|
|
9
9
|
|
|
10
10
|
// src/builder/index.ts
|
|
@@ -812,7 +812,14 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
812
812
|
* Register an object type from a schema
|
|
813
813
|
*/
|
|
814
814
|
objectType(config) {
|
|
815
|
-
const {
|
|
815
|
+
const {
|
|
816
|
+
schema,
|
|
817
|
+
description,
|
|
818
|
+
implements: implementsInterfaces,
|
|
819
|
+
directives,
|
|
820
|
+
cacheControl,
|
|
821
|
+
fields
|
|
822
|
+
} = config;
|
|
816
823
|
const name = config.name ?? getSchemaName(schema);
|
|
817
824
|
if (!name) {
|
|
818
825
|
throw new Error(
|
|
@@ -820,7 +827,14 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
820
827
|
);
|
|
821
828
|
}
|
|
822
829
|
const newTypes = new Map(this.state.types);
|
|
823
|
-
newTypes.set(name, {
|
|
830
|
+
newTypes.set(name, {
|
|
831
|
+
name,
|
|
832
|
+
schema,
|
|
833
|
+
description,
|
|
834
|
+
implements: implementsInterfaces,
|
|
835
|
+
directives,
|
|
836
|
+
cacheControl
|
|
837
|
+
});
|
|
824
838
|
let newObjectFields = this.state.objectFields;
|
|
825
839
|
if (fields) {
|
|
826
840
|
newObjectFields = new Map(this.state.objectFields);
|
|
@@ -1189,6 +1203,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
1189
1203
|
const implementedInterfaces = typeReg.implements?.map((name) => interfaceRegistry.get(name)).filter(Boolean) ?? [];
|
|
1190
1204
|
const graphqlType = new GraphQLObjectType({
|
|
1191
1205
|
name: typeName,
|
|
1206
|
+
description: typeReg.description,
|
|
1192
1207
|
fields: () => {
|
|
1193
1208
|
const baseFields = schemaToFields(typeReg.schema, sharedCtx);
|
|
1194
1209
|
const additionalFields = this.state.objectFields.get(typeName);
|
|
@@ -1464,7 +1479,8 @@ var LoaderRegistry = class {
|
|
|
1464
1479
|
this.Service,
|
|
1465
1480
|
Effect.gen(function* () {
|
|
1466
1481
|
const instances = {};
|
|
1467
|
-
for (const
|
|
1482
|
+
for (const name of Object.keys(self.definitions)) {
|
|
1483
|
+
const def = self.definitions[name];
|
|
1468
1484
|
instances[name] = yield* createDataLoader(def);
|
|
1469
1485
|
}
|
|
1470
1486
|
return instances;
|
|
@@ -1484,6 +1500,9 @@ var LoaderRegistry = class {
|
|
|
1484
1500
|
/**
|
|
1485
1501
|
* Load a single value by key.
|
|
1486
1502
|
* This is the most common operation in resolvers.
|
|
1503
|
+
*
|
|
1504
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
1505
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
1487
1506
|
*/
|
|
1488
1507
|
load(name, key) {
|
|
1489
1508
|
const self = this;
|
|
@@ -1496,6 +1515,9 @@ var LoaderRegistry = class {
|
|
|
1496
1515
|
/**
|
|
1497
1516
|
* Load multiple values by keys.
|
|
1498
1517
|
* All keys are batched into a single request.
|
|
1518
|
+
*
|
|
1519
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
1520
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
1499
1521
|
*/
|
|
1500
1522
|
loadMany(name, keys) {
|
|
1501
1523
|
const self = this;
|
|
@@ -1512,35 +1534,39 @@ var LoaderRegistry = class {
|
|
|
1512
1534
|
});
|
|
1513
1535
|
}
|
|
1514
1536
|
};
|
|
1537
|
+
function createSingleDataLoader(def, context) {
|
|
1538
|
+
return new DataLoader(async (keys) => {
|
|
1539
|
+
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1540
|
+
return keys.map((key) => {
|
|
1541
|
+
const item = items.find((i) => def.key(i) === key);
|
|
1542
|
+
if (!item) return new Error(`Not found: ${key}`);
|
|
1543
|
+
return item;
|
|
1544
|
+
});
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
function createGroupedDataLoader(def, context) {
|
|
1548
|
+
return new DataLoader(async (keys) => {
|
|
1549
|
+
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1550
|
+
const map = /* @__PURE__ */ new Map();
|
|
1551
|
+
for (const item of items) {
|
|
1552
|
+
const key = def.groupBy(item);
|
|
1553
|
+
let arr = map.get(key);
|
|
1554
|
+
if (!arr) {
|
|
1555
|
+
arr = [];
|
|
1556
|
+
map.set(key, arr);
|
|
1557
|
+
}
|
|
1558
|
+
arr.push(item);
|
|
1559
|
+
}
|
|
1560
|
+
return keys.map((key) => map.get(key) ?? []);
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1515
1563
|
function createDataLoader(def) {
|
|
1516
1564
|
return Effect.gen(function* () {
|
|
1517
1565
|
const context = yield* Effect.context();
|
|
1518
1566
|
if (def._tag === "single") {
|
|
1519
|
-
|
|
1520
|
-
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1521
|
-
return keys.map((key) => {
|
|
1522
|
-
const item = items.find((i) => def.key(i) === key);
|
|
1523
|
-
if (!item) return new Error(`Not found: ${key}`);
|
|
1524
|
-
return item;
|
|
1525
|
-
});
|
|
1526
|
-
});
|
|
1527
|
-
return loader;
|
|
1567
|
+
return createSingleDataLoader(def, context);
|
|
1528
1568
|
} else {
|
|
1529
|
-
|
|
1530
|
-
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1531
|
-
const map = /* @__PURE__ */ new Map();
|
|
1532
|
-
for (const item of items) {
|
|
1533
|
-
const key = def.groupBy(item);
|
|
1534
|
-
let arr = map.get(key);
|
|
1535
|
-
if (!arr) {
|
|
1536
|
-
arr = [];
|
|
1537
|
-
map.set(key, arr);
|
|
1538
|
-
}
|
|
1539
|
-
arr.push(item);
|
|
1540
|
-
}
|
|
1541
|
-
return keys.map((key) => map.get(key) ?? []);
|
|
1542
|
-
});
|
|
1543
|
-
return loader;
|
|
1569
|
+
return createGroupedDataLoader(def, context);
|
|
1544
1570
|
}
|
|
1545
1571
|
});
|
|
1546
1572
|
}
|
|
@@ -1764,7 +1790,7 @@ var GraphQLRouterConfigFromEnv = Config.all({
|
|
|
1764
1790
|
);
|
|
1765
1791
|
|
|
1766
1792
|
// src/server/graphiql.ts
|
|
1767
|
-
var graphiqlHtml = (endpoint) => `<!DOCTYPE html>
|
|
1793
|
+
var graphiqlHtml = (endpoint, subscriptionEndpoint) => `<!DOCTYPE html>
|
|
1768
1794
|
<html lang="en">
|
|
1769
1795
|
<head>
|
|
1770
1796
|
<meta charset="utf-8" />
|
|
@@ -1792,6 +1818,7 @@ var graphiqlHtml = (endpoint) => `<!DOCTYPE html>
|
|
|
1792
1818
|
<script>
|
|
1793
1819
|
const fetcher = GraphiQL.createFetcher({
|
|
1794
1820
|
url: ${JSON.stringify(endpoint)},
|
|
1821
|
+
subscriptionUrl: ${JSON.stringify(subscriptionEndpoint ?? endpoint)},
|
|
1795
1822
|
});
|
|
1796
1823
|
ReactDOM.createRoot(document.getElementById('graphiql')).render(
|
|
1797
1824
|
React.createElement(GraphiQL, { fetcher })
|
|
@@ -2467,19 +2494,32 @@ var defaultErrorHandler = (cause) => (process.env.NODE_ENV !== "production" ? Ef
|
|
|
2467
2494
|
).pipe(Effect.orDie)
|
|
2468
2495
|
)
|
|
2469
2496
|
);
|
|
2470
|
-
var
|
|
2497
|
+
var GraphQLRequestBodySchema = Schema.Struct({
|
|
2498
|
+
query: Schema.String,
|
|
2499
|
+
variables: Schema.optionalWith(Schema.Record({ key: Schema.String, value: Schema.Unknown }), {
|
|
2500
|
+
as: "Option"
|
|
2501
|
+
}),
|
|
2502
|
+
operationName: Schema.optionalWith(Schema.String, { as: "Option" })
|
|
2503
|
+
});
|
|
2504
|
+
var decodeRequestBody = HttpIncomingMessage.schemaBodyJson(GraphQLRequestBodySchema);
|
|
2505
|
+
var parseGraphQLQuery = (query2, extensionsService) => {
|
|
2471
2506
|
try {
|
|
2472
2507
|
const document = parse(query2);
|
|
2473
|
-
return { ok: true, document };
|
|
2508
|
+
return Effect.succeed({ ok: true, document });
|
|
2474
2509
|
} catch (parseError) {
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2510
|
+
return extensionsService.get().pipe(
|
|
2511
|
+
Effect.flatMap(
|
|
2512
|
+
(extensionData) => HttpServerResponse.json({
|
|
2513
|
+
errors: [{ message: String(parseError) }],
|
|
2514
|
+
extensions: Object.keys(extensionData).length > 0 ? extensionData : void 0
|
|
2515
|
+
}).pipe(
|
|
2516
|
+
Effect.orDie,
|
|
2517
|
+
Effect.map((response) => ({ ok: false, response }))
|
|
2518
|
+
)
|
|
2519
|
+
)
|
|
2520
|
+
);
|
|
2481
2521
|
}
|
|
2482
|
-
}
|
|
2522
|
+
};
|
|
2483
2523
|
var runComplexityValidation = (body, schema, fieldComplexities, complexityConfig) => {
|
|
2484
2524
|
if (!complexityConfig) {
|
|
2485
2525
|
return Effect.void;
|
|
@@ -2499,8 +2539,9 @@ var runComplexityValidation = (body, schema, fieldComplexities, complexityConfig
|
|
|
2499
2539
|
)
|
|
2500
2540
|
);
|
|
2501
2541
|
};
|
|
2502
|
-
var
|
|
2503
|
-
|
|
2542
|
+
var isPromiseLike = (value) => value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
2543
|
+
var executeGraphQLQuery = (schema, document, variables, operationName, runtime) => {
|
|
2544
|
+
const tryExecute = Effect.try({
|
|
2504
2545
|
try: () => execute$1({
|
|
2505
2546
|
schema,
|
|
2506
2547
|
document,
|
|
@@ -2510,33 +2551,34 @@ var executeGraphQLQuery = (schema, document, variables, operationName, runtime)
|
|
|
2510
2551
|
}),
|
|
2511
2552
|
catch: (error) => new Error(String(error))
|
|
2512
2553
|
});
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
()
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
})
|
|
2520
|
-
|
|
2554
|
+
return tryExecute.pipe(
|
|
2555
|
+
Effect.flatMap((executeResult) => {
|
|
2556
|
+
if (isPromiseLike(executeResult)) {
|
|
2557
|
+
return Effect.promise(() => executeResult);
|
|
2558
|
+
}
|
|
2559
|
+
return Effect.succeed(executeResult);
|
|
2560
|
+
})
|
|
2561
|
+
);
|
|
2562
|
+
};
|
|
2563
|
+
var computeCacheControlHeader = (document, operationName, schema, cacheHints, cacheControlConfig) => {
|
|
2521
2564
|
if (cacheControlConfig?.enabled === false || cacheControlConfig?.calculateHttpHeaders === false) {
|
|
2522
|
-
return void 0;
|
|
2565
|
+
return Effect.succeed(void 0);
|
|
2523
2566
|
}
|
|
2524
2567
|
const operations = document.definitions.filter(
|
|
2525
2568
|
(d) => d.kind === Kind.OPERATION_DEFINITION
|
|
2526
2569
|
);
|
|
2527
2570
|
const operation = operationName ? operations.find((o) => o.name?.value === operationName) : operations[0];
|
|
2528
2571
|
if (!operation || operation.operation === "mutation") {
|
|
2529
|
-
return void 0;
|
|
2572
|
+
return Effect.succeed(void 0);
|
|
2530
2573
|
}
|
|
2531
|
-
|
|
2574
|
+
return computeCachePolicy({
|
|
2532
2575
|
document,
|
|
2533
2576
|
operation,
|
|
2534
2577
|
schema,
|
|
2535
2578
|
cacheHints,
|
|
2536
2579
|
config: cacheControlConfig ?? {}
|
|
2537
|
-
});
|
|
2538
|
-
|
|
2539
|
-
});
|
|
2580
|
+
}).pipe(Effect.map(toCacheControlHeader));
|
|
2581
|
+
};
|
|
2540
2582
|
var buildGraphQLResponse = (result, extensionData, cacheControlHeader) => {
|
|
2541
2583
|
const finalResult = Object.keys(extensionData).length > 0 ? {
|
|
2542
2584
|
...result,
|
|
@@ -2574,7 +2616,12 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2574
2616
|
const extensionsService = yield* makeExtensionsService();
|
|
2575
2617
|
const runtime = yield* Effect.runtime();
|
|
2576
2618
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
2577
|
-
const
|
|
2619
|
+
const parsedBody = yield* decodeRequestBody(request);
|
|
2620
|
+
const body = {
|
|
2621
|
+
query: parsedBody.query,
|
|
2622
|
+
variables: parsedBody.variables._tag === "Some" ? parsedBody.variables.value : void 0,
|
|
2623
|
+
operationName: parsedBody.operationName._tag === "Some" ? parsedBody.operationName.value : void 0
|
|
2624
|
+
};
|
|
2578
2625
|
const parseResult = yield* parseGraphQLQuery(body.query, extensionsService);
|
|
2579
2626
|
if (!parseResult.ok) {
|
|
2580
2627
|
return parseResult.response;
|
|
@@ -2583,7 +2630,7 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2583
2630
|
yield* runParseHooks(extensions, body.query, document).pipe(
|
|
2584
2631
|
Effect.provideService(ExtensionsService, extensionsService)
|
|
2585
2632
|
);
|
|
2586
|
-
const validationRules = resolvedConfig.introspection ? void 0 :
|
|
2633
|
+
const validationRules = resolvedConfig.introspection ? void 0 : specifiedRules.concat(NoSchemaIntrospectionCustomRule);
|
|
2587
2634
|
const validationErrors = validate(schema, document, validationRules);
|
|
2588
2635
|
yield* runValidateHooks(extensions, document, validationErrors).pipe(
|
|
2589
2636
|
Effect.provideService(ExtensionsService, extensionsService)
|
|
@@ -2644,9 +2691,12 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2644
2691
|
HttpRouter.post(resolvedConfig.path, graphqlHandler)
|
|
2645
2692
|
);
|
|
2646
2693
|
if (resolvedConfig.graphiql) {
|
|
2647
|
-
const { path, endpoint } = resolvedConfig.graphiql;
|
|
2694
|
+
const { path, endpoint, subscriptionEndpoint } = resolvedConfig.graphiql;
|
|
2648
2695
|
router = router.pipe(
|
|
2649
|
-
HttpRouter.get(
|
|
2696
|
+
HttpRouter.get(
|
|
2697
|
+
path,
|
|
2698
|
+
HttpServerResponse.html(graphiqlHtml(endpoint, subscriptionEndpoint))
|
|
2699
|
+
)
|
|
2650
2700
|
);
|
|
2651
2701
|
}
|
|
2652
2702
|
return router;
|