@effect-gql/core 1.4.6 → 1.4.8

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/index.cjs CHANGED
@@ -38,7 +38,15 @@ var isIntegerType = (ast) => {
38
38
  const annotations = refinement.annotations;
39
39
  if (annotations) {
40
40
  const identifier = AST__namespace.getIdentifierAnnotation(refinement);
41
- if (identifier._tag === "Some" && identifier.value === "Int") {
41
+ if (identifier._tag === "Some") {
42
+ const id = identifier.value;
43
+ if (id === "Int" || id.includes("Int")) {
44
+ return true;
45
+ }
46
+ }
47
+ const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
48
+ const jsonSchema = annotations[JSONSchemaSymbol];
49
+ if (jsonSchema && jsonSchema.type === "integer") {
42
50
  return true;
43
51
  }
44
52
  }
@@ -106,7 +114,8 @@ var toGraphQLType = (schema) => {
106
114
  if (fieldName === "_tag") continue;
107
115
  const fieldSchema = S2__namespace.make(field2.type);
108
116
  let fieldType = toGraphQLType(fieldSchema);
109
- if (!field2.isOptional) {
117
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
118
+ if (!field2.isOptional && !isOptionField) {
110
119
  fieldType = new graphql.GraphQLNonNull(fieldType);
111
120
  }
112
121
  fields[fieldName] = { type: fieldType };
@@ -182,7 +191,8 @@ var toGraphQLInputType = (schema) => {
182
191
  if (fieldName === "_tag") continue;
183
192
  const fieldSchema = S2__namespace.make(field2.type);
184
193
  let fieldType = toGraphQLInputType(fieldSchema);
185
- if (!field2.isOptional) {
194
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
195
+ if (!field2.isOptional && !isOptionField) {
186
196
  fieldType = new graphql.GraphQLNonNull(fieldType);
187
197
  }
188
198
  fields[fieldName] = { type: fieldType };
@@ -245,7 +255,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
245
255
  if (fieldName === "_tag") continue;
246
256
  const fieldSchema = S2__namespace.make(field2.type);
247
257
  let fieldType = toGraphQLType(fieldSchema);
248
- if (!field2.isOptional) {
258
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
259
+ if (!field2.isOptional && !isOptionField) {
249
260
  fieldType = new graphql.GraphQLNonNull(fieldType);
250
261
  }
251
262
  fields[fieldName] = { type: fieldType };
@@ -277,7 +288,8 @@ var toGraphQLArgs = (schema) => {
277
288
  if (fieldName === "_tag") continue;
278
289
  const fieldSchema = S2__namespace.make(field2.type);
279
290
  let fieldType = toGraphQLInputType(fieldSchema);
280
- if (!field2.isOptional) {
291
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
292
+ if (!field2.isOptional && !isOptionField) {
281
293
  fieldType = new graphql.GraphQLNonNull(fieldType);
282
294
  }
283
295
  args[fieldName] = { type: fieldType };
@@ -1651,15 +1663,25 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1651
1663
  }
1652
1664
  /**
1653
1665
  * Build the GraphQL schema (no services required)
1666
+ *
1667
+ * Uses a two-phase approach:
1668
+ * 1. Phase 1: Build enum and input registries first (these may be referenced by other types)
1669
+ * 2. Phase 2: Build interface, object, and union types (which may reference inputs in args)
1670
+ *
1671
+ * This ensures that when object type fields with args are processed,
1672
+ * all registered input types are already available in the inputRegistry.
1654
1673
  */
1655
1674
  buildSchema() {
1656
- const directiveRegistry = this.buildDirectiveRegistry();
1657
1675
  const enumRegistry = this.buildEnumRegistry();
1658
1676
  const inputRegistry = this.buildInputRegistry(enumRegistry);
1659
- const interfaceRegistry = this.buildInterfaceRegistry(enumRegistry);
1677
+ const inputTypeLookupCache = buildInputTypeLookupCache(this.state.inputs, this.state.enums);
1678
+ const directiveRegistry = this.buildDirectiveRegistry(enumRegistry, inputRegistry, inputTypeLookupCache);
1679
+ const interfaceRegistry = this.buildInterfaceRegistry(enumRegistry, inputRegistry, inputTypeLookupCache);
1660
1680
  const { typeRegistry, unionRegistry } = this.buildTypeAndUnionRegistries(
1661
1681
  enumRegistry,
1662
- interfaceRegistry
1682
+ interfaceRegistry,
1683
+ inputRegistry,
1684
+ inputTypeLookupCache
1663
1685
  );
1664
1686
  const fieldCtx = this.createFieldBuilderContext(
1665
1687
  typeRegistry,
@@ -1683,9 +1705,8 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1683
1705
  subscriptionFields
1684
1706
  });
1685
1707
  }
1686
- buildDirectiveRegistry() {
1708
+ buildDirectiveRegistry(enumRegistry, inputRegistry, cache) {
1687
1709
  const registry = /* @__PURE__ */ new Map();
1688
- const cache = buildInputTypeLookupCache(this.state.inputs, this.state.enums);
1689
1710
  for (const [name, reg] of this.state.directives) {
1690
1711
  const graphqlDirective = new graphql.GraphQLDirective({
1691
1712
  name,
@@ -1693,8 +1714,8 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1693
1714
  locations: [...reg.locations],
1694
1715
  args: reg.args ? toGraphQLArgsWithRegistry(
1695
1716
  reg.args,
1696
- /* @__PURE__ */ new Map(),
1697
- /* @__PURE__ */ new Map(),
1717
+ enumRegistry,
1718
+ inputRegistry,
1698
1719
  this.state.inputs,
1699
1720
  this.state.enums,
1700
1721
  cache
@@ -1744,7 +1765,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1744
1765
  }
1745
1766
  return registry;
1746
1767
  }
1747
- buildInterfaceRegistry(enumRegistry) {
1768
+ buildInterfaceRegistry(enumRegistry, inputRegistry, _cache) {
1748
1769
  const registry = /* @__PURE__ */ new Map();
1749
1770
  const typeRegistry = /* @__PURE__ */ new Map();
1750
1771
  const unionRegistry = /* @__PURE__ */ new Map();
@@ -1770,7 +1791,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1770
1791
  }
1771
1792
  return registry;
1772
1793
  }
1773
- buildTypeAndUnionRegistries(enumRegistry, interfaceRegistry) {
1794
+ buildTypeAndUnionRegistries(enumRegistry, interfaceRegistry, inputRegistry, inputTypeLookupCache) {
1774
1795
  const typeRegistry = /* @__PURE__ */ new Map();
1775
1796
  const unionRegistry = /* @__PURE__ */ new Map();
1776
1797
  const sharedCtx = {
@@ -1779,18 +1800,19 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1779
1800
  enums: this.state.enums,
1780
1801
  unions: this.state.unions,
1781
1802
  inputs: this.state.inputs,
1782
- typeRegistry,
1783
- interfaceRegistry,
1784
- enumRegistry,
1785
- unionRegistry};
1786
- buildReverseLookups(sharedCtx);
1787
- const sharedFieldCtx = this.createFieldBuilderContext(
1788
1803
  typeRegistry,
1789
1804
  interfaceRegistry,
1790
1805
  enumRegistry,
1791
1806
  unionRegistry,
1792
- /* @__PURE__ */ new Map()
1793
- );
1807
+ inputRegistry
1808
+ };
1809
+ buildReverseLookups(sharedCtx);
1810
+ const sharedFieldCtx = {
1811
+ ...sharedCtx,
1812
+ directiveRegistrations: this.state.directives,
1813
+ middlewares: this.state.middlewares,
1814
+ inputTypeLookupCache
1815
+ };
1794
1816
  for (const [typeName, typeReg] of this.state.types) {
1795
1817
  const implementedInterfaces = typeReg.implements?.map((name) => interfaceRegistry.get(name)).filter(Boolean) ?? [];
1796
1818
  const graphqlType = new graphql.GraphQLObjectType({