@effect-gql/core 1.0.0 → 1.1.1
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 +27 -1
- 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 +141 -74
- package/index.cjs.map +1 -1
- package/index.d.cts +9 -3
- package/index.d.ts +9 -3
- package/index.js +143 -76
- 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 +88 -47
- 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 +91 -50
- 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,11 +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';
|
|
8
|
-
import { makeServer } from 'graphql-ws';
|
|
7
|
+
import { HttpIncomingMessage, HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
|
|
9
8
|
|
|
10
9
|
// src/builder/index.ts
|
|
11
10
|
var isIntegerType = (ast) => {
|
|
@@ -812,7 +811,14 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
812
811
|
* Register an object type from a schema
|
|
813
812
|
*/
|
|
814
813
|
objectType(config) {
|
|
815
|
-
const {
|
|
814
|
+
const {
|
|
815
|
+
schema,
|
|
816
|
+
description,
|
|
817
|
+
implements: implementsInterfaces,
|
|
818
|
+
directives,
|
|
819
|
+
cacheControl,
|
|
820
|
+
fields
|
|
821
|
+
} = config;
|
|
816
822
|
const name = config.name ?? getSchemaName(schema);
|
|
817
823
|
if (!name) {
|
|
818
824
|
throw new Error(
|
|
@@ -820,7 +826,14 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
820
826
|
);
|
|
821
827
|
}
|
|
822
828
|
const newTypes = new Map(this.state.types);
|
|
823
|
-
newTypes.set(name, {
|
|
829
|
+
newTypes.set(name, {
|
|
830
|
+
name,
|
|
831
|
+
schema,
|
|
832
|
+
description,
|
|
833
|
+
implements: implementsInterfaces,
|
|
834
|
+
directives,
|
|
835
|
+
cacheControl
|
|
836
|
+
});
|
|
824
837
|
let newObjectFields = this.state.objectFields;
|
|
825
838
|
if (fields) {
|
|
826
839
|
newObjectFields = new Map(this.state.objectFields);
|
|
@@ -1189,6 +1202,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
|
|
|
1189
1202
|
const implementedInterfaces = typeReg.implements?.map((name) => interfaceRegistry.get(name)).filter(Boolean) ?? [];
|
|
1190
1203
|
const graphqlType = new GraphQLObjectType({
|
|
1191
1204
|
name: typeName,
|
|
1205
|
+
description: typeReg.description,
|
|
1192
1206
|
fields: () => {
|
|
1193
1207
|
const baseFields = schemaToFields(typeReg.schema, sharedCtx);
|
|
1194
1208
|
const additionalFields = this.state.objectFields.get(typeName);
|
|
@@ -1464,7 +1478,8 @@ var LoaderRegistry = class {
|
|
|
1464
1478
|
this.Service,
|
|
1465
1479
|
Effect.gen(function* () {
|
|
1466
1480
|
const instances = {};
|
|
1467
|
-
for (const
|
|
1481
|
+
for (const name of Object.keys(self.definitions)) {
|
|
1482
|
+
const def = self.definitions[name];
|
|
1468
1483
|
instances[name] = yield* createDataLoader(def);
|
|
1469
1484
|
}
|
|
1470
1485
|
return instances;
|
|
@@ -1484,6 +1499,9 @@ var LoaderRegistry = class {
|
|
|
1484
1499
|
/**
|
|
1485
1500
|
* Load a single value by key.
|
|
1486
1501
|
* This is the most common operation in resolvers.
|
|
1502
|
+
*
|
|
1503
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
1504
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
1487
1505
|
*/
|
|
1488
1506
|
load(name, key) {
|
|
1489
1507
|
const self = this;
|
|
@@ -1496,6 +1514,9 @@ var LoaderRegistry = class {
|
|
|
1496
1514
|
/**
|
|
1497
1515
|
* Load multiple values by keys.
|
|
1498
1516
|
* All keys are batched into a single request.
|
|
1517
|
+
*
|
|
1518
|
+
* @internal The internal cast is safe because LoaderInstances<Defs> guarantees
|
|
1519
|
+
* that loaders[name] is a DataLoader with the correct key/value types.
|
|
1499
1520
|
*/
|
|
1500
1521
|
loadMany(name, keys) {
|
|
1501
1522
|
const self = this;
|
|
@@ -1512,35 +1533,39 @@ var LoaderRegistry = class {
|
|
|
1512
1533
|
});
|
|
1513
1534
|
}
|
|
1514
1535
|
};
|
|
1536
|
+
function createSingleDataLoader(def, context) {
|
|
1537
|
+
return new DataLoader(async (keys) => {
|
|
1538
|
+
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1539
|
+
return keys.map((key) => {
|
|
1540
|
+
const item = items.find((i) => def.key(i) === key);
|
|
1541
|
+
if (!item) return new Error(`Not found: ${key}`);
|
|
1542
|
+
return item;
|
|
1543
|
+
});
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
function createGroupedDataLoader(def, context) {
|
|
1547
|
+
return new DataLoader(async (keys) => {
|
|
1548
|
+
const items = await Effect.runPromise(def.batch(keys).pipe(Effect.provide(context)));
|
|
1549
|
+
const map = /* @__PURE__ */ new Map();
|
|
1550
|
+
for (const item of items) {
|
|
1551
|
+
const key = def.groupBy(item);
|
|
1552
|
+
let arr = map.get(key);
|
|
1553
|
+
if (!arr) {
|
|
1554
|
+
arr = [];
|
|
1555
|
+
map.set(key, arr);
|
|
1556
|
+
}
|
|
1557
|
+
arr.push(item);
|
|
1558
|
+
}
|
|
1559
|
+
return keys.map((key) => map.get(key) ?? []);
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1515
1562
|
function createDataLoader(def) {
|
|
1516
1563
|
return Effect.gen(function* () {
|
|
1517
1564
|
const context = yield* Effect.context();
|
|
1518
1565
|
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;
|
|
1566
|
+
return createSingleDataLoader(def, context);
|
|
1528
1567
|
} 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;
|
|
1568
|
+
return createGroupedDataLoader(def, context);
|
|
1544
1569
|
}
|
|
1545
1570
|
});
|
|
1546
1571
|
}
|
|
@@ -1764,7 +1789,7 @@ var GraphQLRouterConfigFromEnv = Config.all({
|
|
|
1764
1789
|
);
|
|
1765
1790
|
|
|
1766
1791
|
// src/server/graphiql.ts
|
|
1767
|
-
var graphiqlHtml = (endpoint) => `<!DOCTYPE html>
|
|
1792
|
+
var graphiqlHtml = (endpoint, subscriptionEndpoint) => `<!DOCTYPE html>
|
|
1768
1793
|
<html lang="en">
|
|
1769
1794
|
<head>
|
|
1770
1795
|
<meta charset="utf-8" />
|
|
@@ -1792,6 +1817,7 @@ var graphiqlHtml = (endpoint) => `<!DOCTYPE html>
|
|
|
1792
1817
|
<script>
|
|
1793
1818
|
const fetcher = GraphiQL.createFetcher({
|
|
1794
1819
|
url: ${JSON.stringify(endpoint)},
|
|
1820
|
+
subscriptionUrl: ${JSON.stringify(subscriptionEndpoint ?? endpoint)},
|
|
1795
1821
|
});
|
|
1796
1822
|
ReactDOM.createRoot(document.getElementById('graphiql')).render(
|
|
1797
1823
|
React.createElement(GraphiQL, { fetcher })
|
|
@@ -2467,19 +2493,32 @@ var defaultErrorHandler = (cause) => (process.env.NODE_ENV !== "production" ? Ef
|
|
|
2467
2493
|
).pipe(Effect.orDie)
|
|
2468
2494
|
)
|
|
2469
2495
|
);
|
|
2470
|
-
var
|
|
2496
|
+
var GraphQLRequestBodySchema = Schema.Struct({
|
|
2497
|
+
query: Schema.String,
|
|
2498
|
+
variables: Schema.optionalWith(Schema.Record({ key: Schema.String, value: Schema.Unknown }), {
|
|
2499
|
+
as: "Option"
|
|
2500
|
+
}),
|
|
2501
|
+
operationName: Schema.optionalWith(Schema.String, { as: "Option" })
|
|
2502
|
+
});
|
|
2503
|
+
var decodeRequestBody = HttpIncomingMessage.schemaBodyJson(GraphQLRequestBodySchema);
|
|
2504
|
+
var parseGraphQLQuery = (query2, extensionsService) => {
|
|
2471
2505
|
try {
|
|
2472
2506
|
const document = parse(query2);
|
|
2473
|
-
return { ok: true, document };
|
|
2507
|
+
return Effect.succeed({ ok: true, document });
|
|
2474
2508
|
} catch (parseError) {
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2509
|
+
return extensionsService.get().pipe(
|
|
2510
|
+
Effect.flatMap(
|
|
2511
|
+
(extensionData) => HttpServerResponse.json({
|
|
2512
|
+
errors: [{ message: String(parseError) }],
|
|
2513
|
+
extensions: Object.keys(extensionData).length > 0 ? extensionData : void 0
|
|
2514
|
+
}).pipe(
|
|
2515
|
+
Effect.orDie,
|
|
2516
|
+
Effect.map((response) => ({ ok: false, response }))
|
|
2517
|
+
)
|
|
2518
|
+
)
|
|
2519
|
+
);
|
|
2481
2520
|
}
|
|
2482
|
-
}
|
|
2521
|
+
};
|
|
2483
2522
|
var runComplexityValidation = (body, schema, fieldComplexities, complexityConfig) => {
|
|
2484
2523
|
if (!complexityConfig) {
|
|
2485
2524
|
return Effect.void;
|
|
@@ -2499,8 +2538,9 @@ var runComplexityValidation = (body, schema, fieldComplexities, complexityConfig
|
|
|
2499
2538
|
)
|
|
2500
2539
|
);
|
|
2501
2540
|
};
|
|
2502
|
-
var
|
|
2503
|
-
|
|
2541
|
+
var isPromiseLike = (value) => value !== null && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
2542
|
+
var executeGraphQLQuery = (schema, document, variables, operationName, runtime) => {
|
|
2543
|
+
const tryExecute = Effect.try({
|
|
2504
2544
|
try: () => execute$1({
|
|
2505
2545
|
schema,
|
|
2506
2546
|
document,
|
|
@@ -2510,33 +2550,34 @@ var executeGraphQLQuery = (schema, document, variables, operationName, runtime)
|
|
|
2510
2550
|
}),
|
|
2511
2551
|
catch: (error) => new Error(String(error))
|
|
2512
2552
|
});
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
()
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
})
|
|
2520
|
-
|
|
2553
|
+
return tryExecute.pipe(
|
|
2554
|
+
Effect.flatMap((executeResult) => {
|
|
2555
|
+
if (isPromiseLike(executeResult)) {
|
|
2556
|
+
return Effect.promise(() => executeResult);
|
|
2557
|
+
}
|
|
2558
|
+
return Effect.succeed(executeResult);
|
|
2559
|
+
})
|
|
2560
|
+
);
|
|
2561
|
+
};
|
|
2562
|
+
var computeCacheControlHeader = (document, operationName, schema, cacheHints, cacheControlConfig) => {
|
|
2521
2563
|
if (cacheControlConfig?.enabled === false || cacheControlConfig?.calculateHttpHeaders === false) {
|
|
2522
|
-
return void 0;
|
|
2564
|
+
return Effect.succeed(void 0);
|
|
2523
2565
|
}
|
|
2524
2566
|
const operations = document.definitions.filter(
|
|
2525
2567
|
(d) => d.kind === Kind.OPERATION_DEFINITION
|
|
2526
2568
|
);
|
|
2527
2569
|
const operation = operationName ? operations.find((o) => o.name?.value === operationName) : operations[0];
|
|
2528
2570
|
if (!operation || operation.operation === "mutation") {
|
|
2529
|
-
return void 0;
|
|
2571
|
+
return Effect.succeed(void 0);
|
|
2530
2572
|
}
|
|
2531
|
-
|
|
2573
|
+
return computeCachePolicy({
|
|
2532
2574
|
document,
|
|
2533
2575
|
operation,
|
|
2534
2576
|
schema,
|
|
2535
2577
|
cacheHints,
|
|
2536
2578
|
config: cacheControlConfig ?? {}
|
|
2537
|
-
});
|
|
2538
|
-
|
|
2539
|
-
});
|
|
2579
|
+
}).pipe(Effect.map(toCacheControlHeader));
|
|
2580
|
+
};
|
|
2540
2581
|
var buildGraphQLResponse = (result, extensionData, cacheControlHeader) => {
|
|
2541
2582
|
const finalResult = Object.keys(extensionData).length > 0 ? {
|
|
2542
2583
|
...result,
|
|
@@ -2574,7 +2615,12 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2574
2615
|
const extensionsService = yield* makeExtensionsService();
|
|
2575
2616
|
const runtime = yield* Effect.runtime();
|
|
2576
2617
|
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
2577
|
-
const
|
|
2618
|
+
const parsedBody = yield* decodeRequestBody(request);
|
|
2619
|
+
const body = {
|
|
2620
|
+
query: parsedBody.query,
|
|
2621
|
+
variables: parsedBody.variables._tag === "Some" ? parsedBody.variables.value : void 0,
|
|
2622
|
+
operationName: parsedBody.operationName._tag === "Some" ? parsedBody.operationName.value : void 0
|
|
2623
|
+
};
|
|
2578
2624
|
const parseResult = yield* parseGraphQLQuery(body.query, extensionsService);
|
|
2579
2625
|
if (!parseResult.ok) {
|
|
2580
2626
|
return parseResult.response;
|
|
@@ -2583,7 +2629,7 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2583
2629
|
yield* runParseHooks(extensions, body.query, document).pipe(
|
|
2584
2630
|
Effect.provideService(ExtensionsService, extensionsService)
|
|
2585
2631
|
);
|
|
2586
|
-
const validationRules = resolvedConfig.introspection ? void 0 :
|
|
2632
|
+
const validationRules = resolvedConfig.introspection ? void 0 : specifiedRules.concat(NoSchemaIntrospectionCustomRule);
|
|
2587
2633
|
const validationErrors = validate(schema, document, validationRules);
|
|
2588
2634
|
yield* runValidateHooks(extensions, document, validationErrors).pipe(
|
|
2589
2635
|
Effect.provideService(ExtensionsService, extensionsService)
|
|
@@ -2644,9 +2690,12 @@ var makeGraphQLRouter = (schema, layer, options = {}) => {
|
|
|
2644
2690
|
HttpRouter.post(resolvedConfig.path, graphqlHandler)
|
|
2645
2691
|
);
|
|
2646
2692
|
if (resolvedConfig.graphiql) {
|
|
2647
|
-
const { path, endpoint } = resolvedConfig.graphiql;
|
|
2693
|
+
const { path, endpoint, subscriptionEndpoint } = resolvedConfig.graphiql;
|
|
2648
2694
|
router = router.pipe(
|
|
2649
|
-
HttpRouter.get(
|
|
2695
|
+
HttpRouter.get(
|
|
2696
|
+
path,
|
|
2697
|
+
HttpServerResponse.html(graphiqlHtml(endpoint, subscriptionEndpoint))
|
|
2698
|
+
)
|
|
2650
2699
|
);
|
|
2651
2700
|
}
|
|
2652
2701
|
return router;
|
|
@@ -2821,27 +2870,45 @@ var runConnectionLifecycle = (socket, wsServer, extra) => Effect.gen(function* (
|
|
|
2821
2870
|
Effect.catchAllCause(() => Effect.void),
|
|
2822
2871
|
Effect.scoped
|
|
2823
2872
|
);
|
|
2873
|
+
var importGraphqlWs = Effect.tryPromise({
|
|
2874
|
+
try: () => import('graphql-ws'),
|
|
2875
|
+
catch: () => new Error(
|
|
2876
|
+
"graphql-ws is required for WebSocket subscriptions. Install it with: npm install graphql-ws"
|
|
2877
|
+
)
|
|
2878
|
+
});
|
|
2824
2879
|
var makeGraphQLWSHandler = (schema, layer, options) => {
|
|
2825
2880
|
const complexityConfig = options?.complexity;
|
|
2826
2881
|
const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2882
|
+
let wsServerPromise = null;
|
|
2883
|
+
const getOrCreateServer = async () => {
|
|
2884
|
+
if (!wsServerPromise) {
|
|
2885
|
+
wsServerPromise = Effect.runPromise(importGraphqlWs).then(({ makeServer }) => {
|
|
2886
|
+
const serverOptions = {
|
|
2887
|
+
schema,
|
|
2888
|
+
context: async (ctx) => {
|
|
2889
|
+
const extra = ctx.extra;
|
|
2890
|
+
return {
|
|
2891
|
+
runtime: extra.runtime,
|
|
2892
|
+
...extra.connectionParams
|
|
2893
|
+
};
|
|
2894
|
+
},
|
|
2895
|
+
subscribe: async (args) => subscribe(args),
|
|
2896
|
+
onConnect: makeOnConnectHandler(options),
|
|
2897
|
+
onDisconnect: makeOnDisconnectHandler(options),
|
|
2898
|
+
onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
|
|
2899
|
+
onComplete: makeOnCompleteHandler(options),
|
|
2900
|
+
onError: makeOnErrorHandler(options)
|
|
2901
|
+
};
|
|
2902
|
+
return makeServer(serverOptions);
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
return wsServerPromise;
|
|
2842
2906
|
};
|
|
2843
|
-
const wsServer = makeServer(serverOptions);
|
|
2844
2907
|
return (socket) => Effect.gen(function* () {
|
|
2908
|
+
const wsServer = yield* Effect.tryPromise({
|
|
2909
|
+
try: () => getOrCreateServer(),
|
|
2910
|
+
catch: (error) => error
|
|
2911
|
+
});
|
|
2845
2912
|
const runtime = yield* Effect.provide(Effect.runtime(), layer);
|
|
2846
2913
|
const extra = {
|
|
2847
2914
|
socket,
|