-
Notifications
You must be signed in to change notification settings - Fork 6
Is it possible to drop the ()
from the end of every property access?
#98
Comments
Getters are not in the RC but are definitely an API improvement I’ve been thinking about. Good reinforcement to see that someone else thought of it too :) I don’t know of a way of accomplishing the second example exactly (at least with what JS/TS support today). We could support static arrays in place of selector callbacks. Not sure if that would be better though..part of the beauty of the callbacks is that they give you the appropriate selector object Good feedback though, keep it coming! |
Yeah once I'd sent that last one I realised my mistake with the FWIW on a second look, the getters-based one looks great to my eyes, makes the nested The only other improvement I thought of was using query.getPostById({ id: post1 }, (t) => [
t.slug,
t.author((t) => [
t.username,
t.avatar
]),
]) This really looks great to me, I could see myself writing that instead of string-based GQL tags pretty muche every time... Oh and just because I'm a monster, would this ever be possible? query
.getPostById({ id: post1 }, (p) => p
.slug
.author((a) => a
.username
.avatar
)
) I'm not suggesting it, more just curious. Prettier kinda obliterates anyway: query.getPostById({ id: post1 }, (p) => p.slug.author((a) => a.username.avatar)) Now I wanna trawl TC39 proposals for any new syntax to make fancy new DSLs with :) I had a glance at the pipeline operator but I don't think that helps. Anyway, fun to explore :) |
Totally agree. The 1.x RC removes the requirement for an operation name as the first argument. There's also an undocumented option in the pre-1.x version (e.g
import { Executor } from '@timkendall/tql'
import { MyClient } from './generated'
const client = new MyClient(new Executor({ uri: 'http://localhost:8080' }))
await client.query.getPostById({ id: post1 }, (t) => [
t.slug(),
t.author((t) => [
t.username(),
t.avatar(),
]),
])
Hmm so a combination between the callback and a more traditional builder API...I'll have to think about that. Not sure if it's cleaner IMO though.
Ha same! If JS/TypeScript offered an implicit |
The getter syntax is such a great idea! It would totally become my number 1 preferred syntax over all the alternatives. 🤩 |
Maybe this is changed with the new RC, but I was wondering if it's possible to make fields getters instead of function calls? Atm I have this:
Any way it could be changed to this?
And while I'm dreamcoding, how about this?
I mean I have literally no idea how the typescript reflection stuff works but I thought I'd ask!
The text was updated successfully, but these errors were encountered: