-
Notifications
You must be signed in to change notification settings - Fork 42
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
Qn: possible to get the type of a sub object in query #80
Comments
I guess I'm probably looking for a directive (like |
Right now the whole response is just one big object. There is no way to get the type of the part of the response, unfortunately. |
ahh lameeee! Well I've been curious about what writing ppxs is like anyway so I might give adding something a go over the next couple of weeks 😄 |
It's possible: module Meta = {
module type mt_ret = {type t;};
type typed_ret('a) = (module mt_ret with type t = 'a);
let ret_type = (type a, _: _ => a): typed_ret(a) => {
module MT_Ret = {
type t = a;
};
(module MT_Ret);
};
};
module GetUser = [%graphql
{|
{
users @bsRecord {
first_name
last_name
email
company {
name
}
}
}
|}
];
/** this code will never be executed. It is used only by the compiler to retrieve the type of return */
module MT_Ret = (val Meta.ret_type((json) => GetUser.parse(json)##users[0]##company));
type company = MT_Ret.t; |
Very clever! This looks useful in lots of other places too. |
* adds decoder support to fragments * deletes newline * fixes builds
Say I have the following query:
Is it possible to get the type of company?
The text was updated successfully, but these errors were encountered: