Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1787

How to convert record to object?

$
0
0

I met this problem while dealing with GraphQL + Apollo. There are multiple queries that return structurally equivalent yet nominally different types. I want to handle the these polymorphically (in pseudo-rescript):

let result = switch cases {
| case1 => MyQuery.A.use(arg)
| case2 => MyQuery.B.use(arg)
}

but I can’t, as these two have different types—something like MyQuery.A.A_inner.t and MyQuery.B.B_inner.t. Maybe the coercion operator from v11 might help, but Apollo client bindings + graphql-ppx stack does not support v11 yet. Is Obj.magic the only way to bypass the typechecker?


Viewing all articles
Browse latest Browse all 1787

Trending Articles