I'm off to bed, I just created <https://github.com...
# prisma-whats-new
c
I'm off to bed, I just created https://github.com/cj/jsgql, thought I'd link it here, as it might be useful to some
👍 2
d
looks interesting, but I cannot think of any use case for it 🙂
d
I think it could be useful when programatically generating graphql. Instead of doing a big string concatenation exercise to make the string to pass to gql, you would build an object and then use this to generate the graphql AST from it
d
well i think that string concat is still easier 🙂
d
each to their own but I'm definitely going to give this a try next time I need to generate some dynamic, highly nested graphql - I suspect dealing with objects will be less messy and easier to maintain than strings
c
@dankent exactly right. I got tired of creating lots of
.gql
files, it also felt counter productive as the point of graphql is the freedom to get exactly what you want for each different call. so now with this you can do that 🙂
@Daniel K. string concat is messy if you are doing it all inline, it distracts from your actual code and can make it pretty messy if you're doing it all the time. This does it that for you behind the scenes, so all you deal with is a nice js object 🙂
d
yea well, I find an AST too bloated for it to be able built it easily, it would need another wrapper that could generate with same useful interface, building whole object could be messy same way
d
@cj something that would be useful would be if this would support multiple queries/mutations within a single outer query
That would mean having a methods array rather than than single method property and enabling the alias for each one to be set
c
@dankent you'd just do
[fooGQL, barGQL].map(gql => jsgql(gql))
@Daniel K. I'd love to see an example
d
wouldn't that make separate graphql AST's - I'm talkiing about multiple operations within a single AST
Situations like the one in the link above are often where I end up do dynamic graphql generation, to get things like:
mutation { charmander: createPokemon(name: "Charmander", type: FIRE) { type } bulbasaur: createPokemon(name: "Bulbasaur", type: GRASS) { type } }
c
I can make it do that if you parse an Array to jsgql, the reason I haven't is Apollo client batching does that fo you and more intelligently, which graph.cool supports
meaning you can call apollo.query in multiple places in your app concurrently and it will batch them all together in a single call 🙂
d
Using automated batching doesn't provide guarantees about mutation execution order. Putting multiple aliased mutations in one graphql mutation element guarantees that the mutations will be executed in series
With automated batching, if my mutations end up being sent in separate requests, graphql will execute them in parallel
c
I can add that in if you like, I just hadn't had a use case for it, if I needed something to come after something, I would just nest they query fields like
id customers { id }
@dankent do you have an example use case for that? I'd love to see one as I haven't come across it yet
I'll add the acceptance of an array today though, which will give that output you pasted
d
Two main situations where you want to guarantee serial execution of mutations:
1) You are doing something in the request pipeline that takes time (e.g. an external call) and you want to ensure it completes before you do the next mutation
2) You want subsequent mutations to be cancelled if one before it in the list fails
aliased mutations within a single mutation give you both of these behaviours
Apollo does batching of queries but does not (as far as I know) do any automated batching of mutations
(which is a good thing - if it did, failure of one mutation in the batch could cause other unrelated mutations to fail)
c
for me, I would never use that use case, because now you can't rely on the automatic grapqhql docs, as you now have to specifically tell people, "HEY when you do this mutation don't for get to run this one first!"
I would handle that logic behind the scene so it's just a nice single simple graphql mutation
d
The cases where I have had to do this, it's obvious that the subsequent mutations don't make sense without the first one happening before them. I will be reworking at least some of them as schema extensions to provide a single call but I expect that aliased mutations will still be a useful tool from time to time.
n
@cj @dankent would love for you to chime in here: https://www.graph.cool/forum/t/query-batching-in-graphcool-vs-apollo/409?u=nilan 🙂
notably, Apollo Query Batching is different to "using the same field multiple times in the same GraphQL document-batching"
@cj feel free to share your project here as well: https://www.graph.cool/forum/c/show-tell 🙌
c
@nilan morning. will do! I didn't know about that part of the forum 🙂
🎊 1