Skip to content

Commit e0bbb13

Browse files
drewwestphalclaude
andcommitted
Add ObjectScalar custom-scalar fixtures from zth#583
ValdemarGr's stale PR zth#583 added a schema input shape, two custom scalar modules, and a relay-config registration to reproduce issue zth#582 (encoding doesn't always apply scalar encoders). This commit lifts those fixtures in preparation for a full integration test for zth#582 and broader regression coverage in this PR. ValdemarGr's ObjectScalar serializers and parsers also log to the console, which the harness in a later commit uses to assert which converters actually ran for a given operation. The Datetime and Number serializers in TestsUtils gain similar console.log lines (matching the existing pattern in IntString) so a follow-up zth#407 regression test can verify that a non-array custom scalar variable still has its serializer run when it follows an array-backed scalar variable in the same operation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d468b20 commit e0bbb13

4 files changed

Lines changed: 74 additions & 6 deletions

File tree

packages/rescript-relay/__tests__/TestsUtils.res

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ module Datetime = {
1010
| None => throw(Malformed_date)
1111
| Some(dateStr) => dateStr->Date.fromString
1212
}
13-
let serialize = t =>
14-
t
15-
->Date.toJSON
16-
->Option.getOr("-")
17-
->JSON.Encode.string
13+
let serialize = t => {
14+
// This log is used for testing purposes - do not remove
15+
Console.log("Datetime.serialize")
16+
t->Date.toJSON->Option.getOr("-")->JSON.Encode.string
17+
}
1818
}
1919

2020
module IntString = {
@@ -32,11 +32,54 @@ type number = array<int>
3232

3333
module Number = {
3434
type t = number
35-
let serialize = t => JSON.Encode.float(Float.fromInt(t->Array.reduce(0, (x, y) => y + x)))
35+
let serialize = t => {
36+
// This log is used for testing purposes - do not remove
37+
Console.log("Number.serialize")
38+
JSON.Encode.float(Float.fromInt(t->Array.reduce(0, (x, y) => y + x)))
39+
}
3640

3741
let parse = t =>
3842
switch t->JSON.Decode.float {
3943
| None => throw(Malformed_number)
4044
| Some(_) => []
4145
}
4246
}
47+
48+
type objectScalarPayload = {
49+
a: string,
50+
b?: string,
51+
c?: string,
52+
}
53+
54+
// Custom-scalar shapes used by the regression tests for issues #582 and
55+
// #631. The serializers log so a Jest harness can assert which converters
56+
// actually ran for a given operation — the bug in those issues was that
57+
// converters silently DIDN'T run for fields placed after a custom-scalar
58+
// array in the same selection set.
59+
module ObjectScalar1 = {
60+
type t = objectScalarPayload
61+
let serialize = (_: t) => {
62+
// This log is used for testing purposes - do not remove
63+
Console.log("ObjectScalar1.serialize")
64+
JSON.Encode.string("serialized1")
65+
}
66+
let parse = (_: JSON.t): t => {
67+
// This log is used for testing purposes - do not remove
68+
Console.log("ObjectScalar1.parse")
69+
{a: "parsed1"}
70+
}
71+
}
72+
73+
module ObjectScalar2 = {
74+
type t = objectScalarPayload
75+
let serialize = (_: t) => {
76+
// This log is used for testing purposes - do not remove
77+
Console.log("ObjectScalar2.serialize")
78+
JSON.Encode.string("serialized2")
79+
}
80+
let parse = (_: JSON.t): t => {
81+
// This log is used for testing purposes - do not remove
82+
Console.log("ObjectScalar2.parse")
83+
{a: "parsed2"}
84+
}
85+
}

packages/rescript-relay/__tests__/__generated__/RelaySchemaAssets_graphql.res

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/rescript-relay/__tests__/schema.graphql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ type Mutation {
258258
serializeCustomScalarArray(
259259
input: [IntString!]!
260260
): SerializeCustomScalarArrayPayload
261+
serializeMultipleCustomScalars(
262+
input: SerializeMultipleCustomScalars!
263+
): Boolean
261264
}
262265

263266
type Subscription {
@@ -277,3 +280,11 @@ input Location @oneOf {
277280
byLoc: ByLoc
278281
byId: ID
279282
}
283+
284+
scalar ObjectScalar1
285+
scalar ObjectScalar2
286+
287+
input SerializeMultipleCustomScalars {
288+
os1s: [ObjectScalar1!]!
289+
os2: ObjectScalar2
290+
}

packages/rescript-relay/relay.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module.exports = {
1313
IntString: "TestsUtils.IntString",
1414
JSON: "JSON.t",
1515
Number: "TestsUtils.Number",
16+
ObjectScalar1: "TestsUtils.ObjectScalar1",
17+
ObjectScalar2: "TestsUtils.ObjectScalar2",
1618
},
1719
persistConfig: PERSISTING
1820
? {

0 commit comments

Comments
 (0)