Closed DZakh closed 8 months ago
I've used the pnpm patch for now, since we use rescript-relay V2 anyways. But maybe it may be added to V3:
pnpm patch
rescript-relay
/src/RescriptRelay.res @@ -587,16 +587,18 @@ module Store = { } module RequiredFieldLogger = { - type kind = [#"missing_field.log" | #"missing_field.throw"] - - type arg = {"kind": kind, "owner": string, "fieldPath": string} - - type js = arg => unit - - type t = (~kind: kind, ~owner: string, ~fieldPath: string) => unit - - let toJs: t => js = f => arg => - f(~kind=arg["kind"], ~owner=arg["owner"], ~fieldPath=arg["fieldPath"]) + @tag("kind") + type arg = + | @as("missing_field.log") MissingFieldLog({owner: string, fieldPath: string}) + | @as("missing_field.throw") MissingFieldThrow({owner: string, fieldPath: string}) + | @as("relay_resolver.error") + RelayResolverError({ + owner: string, + fieldPath: string, + error: Js.Exn.t, + }) + + type t = arg => unit } module Environment = { @@ -612,7 +614,7 @@ module Environment = { treatMissingFieldsAsNull: bool, missingFieldHandlers: array<MissingFieldHandler.t>, @optional - requiredFieldLogger: RequiredFieldLogger.js, + requiredFieldLogger: RequiredFieldLogger.t, @optional isServer: bool, } @@ -640,7 +642,7 @@ module Environment = { | Some(handlers) => handlers->Belt.Array.concat([nodeInterfaceMissingFieldHandler]) | None => [nodeInterfaceMissingFieldHandler] }, - ~requiredFieldLogger=?requiredFieldLogger->Belt.Option.map(RequiredFieldLogger.toJs), + ~requiredFieldLogger?, ~isServer?, (), ), /src/RescriptRelay.resi @@ -729,10 +729,19 @@ module Disposable: { /**A required field logger, which gets called when a field annotated with the @required directive was missing from the response*/ module RequiredFieldLogger: { - type kind = [#"missing_field.log" | #"missing_field.throw"] + @tag("kind") + type arg = + | @as("missing_field.log") MissingFieldLog({owner: string, fieldPath: string}) + | @as("missing_field.throw") MissingFieldThrow({owner: string, fieldPath: string}) + | @as("relay_resolver.error") + RelayResolverError({ + owner: string, + fieldPath: string, + error: Js.Exn.t, + }) /**A required field logger, which gets called when a field annotated with the @required directive was missing from the response*/ - type t = (~kind: kind, ~owner: string, ~fieldPath: string) => unit + type t = arg => unit }
PR definitely welcome!
@DZakh PR? ;)
We are still on V2, but I can prepare it during the week
I've used the
pnpm patch
for now, since we userescript-relay
V2 anyways. But maybe it may be added to V3: