@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/builder/index.cjs CHANGED
@@ -33,7 +33,15 @@ var isIntegerType = (ast) => {
33
33
  const annotations = refinement.annotations;
34
34
  if (annotations) {
35
35
  const identifier = AST__namespace.getIdentifierAnnotation(refinement);
36
- if (identifier._tag === "Some" && identifier.value === "Int") {
36
+ if (identifier._tag === "Some") {
37
+ const id = identifier.value;
38
+ if (id === "Int" || id.includes("Int")) {
39
+ return true;
40
+ }
41
+ }
42
+ const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
43
+ const jsonSchema = annotations[JSONSchemaSymbol];
44
+ if (jsonSchema && jsonSchema.type === "integer") {
37
45
  return true;
38
46
  }
39
47
  }
@@ -101,7 +109,8 @@ var toGraphQLType = (schema) => {
101
109
  if (fieldName === "_tag") continue;
102
110
  const fieldSchema = S2__namespace.make(field2.type);
103
111
  let fieldType = toGraphQLType(fieldSchema);
104
- if (!field2.isOptional) {
112
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
113
+ if (!field2.isOptional && !isOptionField) {
105
114
  fieldType = new graphql.GraphQLNonNull(fieldType);
106
115
  }
107
116
  fields[fieldName] = { type: fieldType };
@@ -177,7 +186,8 @@ var toGraphQLInputType = (schema) => {
177
186
  if (fieldName === "_tag") continue;
178
187
  const fieldSchema = S2__namespace.make(field2.type);
179
188
  let fieldType = toGraphQLInputType(fieldSchema);
180
- if (!field2.isOptional) {
189
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
190
+ if (!field2.isOptional && !isOptionField) {
181
191
  fieldType = new graphql.GraphQLNonNull(fieldType);
182
192
  }
183
193
  fields[fieldName] = { type: fieldType };
@@ -228,7 +238,8 @@ var toGraphQLArgs = (schema) => {
228
238
  if (fieldName === "_tag") continue;
229
239
  const fieldSchema = S2__namespace.make(field2.type);
230
240
  let fieldType = toGraphQLInputType(fieldSchema);
231
- if (!field2.isOptional) {
241
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
242
+ if (!field2.isOptional && !isOptionField) {
232
243
  fieldType = new graphql.GraphQLNonNull(fieldType);
233
244
  }
234
245
  args[fieldName] = { type: fieldType };
@@ -1602,15 +1613,25 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1602
1613
  }
1603
1614
  /**
1604
1615
  * Build the GraphQL schema (no services required)
1616
+ *
1617
+ * Uses a two-phase approach:
1618
+ * 1. Phase 1: Build enum and input registries first (these may be referenced by other types)
1619
+ * 2. Phase 2: Build interface, object, and union types (which may reference inputs in args)
1620
+ *
1621
+ * This ensures that when object type fields with args are processed,
1622
+ * all registered input types are already available in the inputRegistry.
1605
1623
  */
1606
1624
  buildSchema() {
1607
- const directiveRegistry = this.buildDirectiveRegistry();
1608
1625
  const enumRegistry = this.buildEnumRegistry();
1609
1626
  const inputRegistry = this.buildInputRegistry(enumRegistry);
1610
- const interfaceRegistry = this.buildInterfaceRegistry(enumRegistry);
1627
+ const inputTypeLookupCache = buildInputTypeLookupCache(this.state.inputs, this.state.enums);
1628
+ const directiveRegistry = this.buildDirectiveRegistry(enumRegistry, inputRegistry, inputTypeLookupCache);
1629
+ const interfaceRegistry = this.buildInterfaceRegistry(enumRegistry, inputRegistry, inputTypeLookupCache);
1611
1630
  const { typeRegistry, unionRegistry } = this.buildTypeAndUnionRegistries(
1612
1631
  enumRegistry,
1613
- interfaceRegistry
1632
+ interfaceRegistry,
1633
+ inputRegistry,
1634
+ inputTypeLookupCache
1614
1635
  );
1615
1636
  const fieldCtx = this.createFieldBuilderContext(
1616
1637
  typeRegistry,
@@ -1634,9 +1655,8 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1634
1655
  subscriptionFields
1635
1656
  });
1636
1657
  }
1637
- buildDirectiveRegistry() {
1658
+ buildDirectiveRegistry(enumRegistry, inputRegistry, cache) {
1638
1659
  const registry = /* @__PURE__ */ new Map();
1639
- const cache = buildInputTypeLookupCache(this.state.inputs, this.state.enums);
1640
1660
  for (const [name, reg] of this.state.directives) {
1641
1661
  const graphqlDirective = new graphql.GraphQLDirective({
1642
1662
  name,
@@ -1644,8 +1664,8 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1644
1664
  locations: [...reg.locations],
1645
1665
  args: reg.args ? toGraphQLArgsWithRegistry(
1646
1666
  reg.args,
1647
- /* @__PURE__ */ new Map(),
1648
- /* @__PURE__ */ new Map(),
1667
+ enumRegistry,
1668
+ inputRegistry,
1649
1669
  this.state.inputs,
1650
1670
  this.state.enums,
1651
1671
  cache
@@ -1695,7 +1715,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1695
1715
  }
1696
1716
  return registry;
1697
1717
  }
1698
- buildInterfaceRegistry(enumRegistry) {
1718
+ buildInterfaceRegistry(enumRegistry, inputRegistry, _cache) {
1699
1719
  const registry = /* @__PURE__ */ new Map();
1700
1720
  const typeRegistry = /* @__PURE__ */ new Map();
1701
1721
  const unionRegistry = /* @__PURE__ */ new Map();
@@ -1721,7 +1741,7 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1721
1741
  }
1722
1742
  return registry;
1723
1743
  }
1724
- buildTypeAndUnionRegistries(enumRegistry, interfaceRegistry) {
1744
+ buildTypeAndUnionRegistries(enumRegistry, interfaceRegistry, inputRegistry, inputTypeLookupCache) {
1725
1745
  const typeRegistry = /* @__PURE__ */ new Map();
1726
1746
  const unionRegistry = /* @__PURE__ */ new Map();
1727
1747
  const sharedCtx = {
@@ -1730,18 +1750,19 @@ var GraphQLSchemaBuilder = class _GraphQLSchemaBuilder {
1730
1750
  enums: this.state.enums,
1731
1751
  unions: this.state.unions,
1732
1752
  inputs: this.state.inputs,
1733
- typeRegistry,
1734
- interfaceRegistry,
1735
- enumRegistry,
1736
- unionRegistry};
1737
- buildReverseLookups(sharedCtx);
1738
- const sharedFieldCtx = this.createFieldBuilderContext(
1739
1753
  typeRegistry,
1740
1754
  interfaceRegistry,
1741
1755
  enumRegistry,
1742
1756
  unionRegistry,
1743
- /* @__PURE__ */ new Map()
1744
- );
1757
+ inputRegistry
1758
+ };
1759
+ buildReverseLookups(sharedCtx);
1760
+ const sharedFieldCtx = {
1761
+ ...sharedCtx,
1762
+ directiveRegistrations: this.state.directives,
1763
+ middlewares: this.state.middlewares,
1764
+ inputTypeLookupCache
1765
+ };
1745
1766
  for (const [typeName, typeReg] of this.state.types) {
1746
1767
  const implementedInterfaces = typeReg.implements?.map((name) => interfaceRegistry.get(name)).filter(Boolean) ?? [];
1747
1768
  const graphqlType = new graphql.GraphQLObjectType({