Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The relay_resolver.error support #478

Closed
DZakh opened this issue Dec 1, 2023 · 3 comments
Closed

The relay_resolver.error support #478

DZakh opened this issue Dec 1, 2023 · 3 comments

Comments

@DZakh
Copy link
Contributor

DZakh commented Dec 1, 2023

I've used the pnpm patch for now, since we use rescript-relay V2 anyways. But maybe it may be added to V3:

/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
 }
@zth
Copy link
Owner

zth commented Dec 1, 2023

PR definitely welcome!

@zth
Copy link
Owner

zth commented Dec 18, 2023

@DZakh PR? ;)

@DZakh
Copy link
Contributor Author

DZakh commented Dec 18, 2023

We are still on V2, but I can prepare it during the week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants