-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Directives #210
Comments
Cool! |
Hey @natew has there been any work on this, I'm actually in need of this feature. I need it to consume Dgraph graphql API, they have a cascade directive that is required for particular queries. |
Joining the brainstorming here. Idea 1I am pulling the same trick as I did in other places, resorting to a leading This one is easier to implement, but more cumbersome to use.
Idea 2This one looks a bit more syntactically pleasing and aligns with the intuition when you think of the proxy as normal javascript objects. i.e. Actual value comes out from the last dot. But this one requires polymorphism in the
Idea 3Anything starts with For example,
|
@vicary I like the first and third ideas, the second one will complicate things, since then The only question would be how to handle multiple directives at the same level? Some examples:
The second one makes more cense since we could use directives without arguments, very clearly. |
To add multiple directives, it works the same way you query multiple fields from the same type. You either store the intermediate in a variable, or by destructuring. For idea 1, const directives = query.queryPost.$directives;
directives.foo; // no inputs
directives.bar({ ... }); // with inputs
const {
queryPost: {
$directives: {
foo,
bar
}
}
} = query;
bar({ ... }); // looks awkward, tbh. For idea 3, const post = query.queryPost;
post["@foo"]; // no inputs
post["@bar"]({ ... }); // with inputs
const {
queryPost: {
["@foo"]: foo, // requires local alias
["@bar"]: bar
}
} = query;
bar({ ... }); // same, looks awkward For me, choosing between |
The first one, has less code between the two, for the case of I'm not yet familiar with how the proxy traps and types are defined in gqless, but I think this could introduce complications for adding directives to graphql scalars, think |
Yes you're right. It only seemed mildly inconvenient to me at first, but it almost defeats the good feelings I had when looking at Honestly I have no proposals good enough for directives right now. |
Indeed, when having that in mind, it's not trivial. directives(query.queryPost.title, [ { foo: { ttl: 20 } }, 'bar' ]) |
Not sure how React-style is supposed to look like. But this syntax kind of aligns with the |
Support for directives would unlock stuff like caching in Hasura.
Not sure how best to enable them in a gqless style. Let's take a few examples:
The top level one is easy enough:
The leaf values are harder, they go could any number of ways...
I think I like a combination of 1.b and 2.b, but open to something more consistent.
Just wanted to open ticket to start discussion.
The text was updated successfully, but these errors were encountered: