Fork me on GitHub
#graphql
<
2018-10-18
>
lxsli08:10:28

@hlship Thanks, I was having trouble understanding it too! I deleted my target folder and as if by magic, the issue went away

orestis12:10:09

I always assumed that I could do a mutation and a query at the same time, but it turns out that’s not true 😞 Seems like a GraphQL constrain — you can do multiple mutations, multiple queries, but not mutations and queries.

domkm15:10:22

@orestis You can't do multiple mutations or queries at the same time. Every request must specify exactly one operation, either implicit by having only one operation or explicit by sending an operation name.

domkm15:10:23

Conceptually, a mutation is just a query where the top-level field has special treatment. The fields returned by the mutation are just query fields. Essentially, a mutation is a write followed by a read.

orestis15:10:44

Really? What’s that talk then about queries been (potentially) done in parallel while mutations being sequential? This is what got me confused.

domkm15:10:30

Ah, so perhaps I misunderstood what you meant by multiple. Apologies. You can have a single mutation execute multiple mutation fields and that does need to be executed serially. In that sense you are correct that a request cannot be for both a mutation and a query at once.

domkm15:10:50

This is a total hack but you could, technically, have mutation fields that don't mutate anything, which would behave the same as query fields (aside from serial/parallel execution).

orestis15:10:53

Aaah right, I think that the eliding of the top level “constructs” (QueryRoot, MutationRoot) can be confusing.

domkm15:10:25

Why do you want to run multiple query fields and mutation fields in one request?

orestis15:10:56

I thought I was able to do something like this:

{ 
  mutation UpdatePartOfThing() { 
    update_thing(...)
  }
  query FetchDependentThang() {
    thang_by_id(...)
  }
}

orestis15:10:24

And my expectation was that UpdatePartOfThing would execute, then FetchDependentThang would execute.

orestis15:10:11

This way if I know about dependencies already, I wouldn’t have to issue a second network request.

domkm15:10:13

I see. So the typical way this is handled is by having update_thing return an object of dependent_thangs

domkm15:10:41

A mutation is a write followed by a read, the return fields of the mutation should be reconciled with the data you already have

orestis15:10:49

Yes, that would be the way to do it.

orestis15:10:40

In some sense GraphQL exposes quite heavily the fact that the way we’ve been building SPAs for quite some time now is very ad-hoc — the fact that it works best with a client-side database means that noone has been using a proper one for quite some time.

orestis15:10:54

I mean “reconcile with the data you already have” is not a trivial thing to write.

orestis15:10:23

Sometimes I just want to stop doing all that SPA stuff and issue GraphQL queries server-side, then just render a whole bunch of HTML 🙂

domkm15:10:02

It's not at all. That's why writing a 99% correct stateful GraphQL client is incredibly hard.

domkm15:10:42

Perfectly valid technique 😉 GraphQL isn't only for browser/mobile clients.

domkm15:10:41

@hlship If it's not too much trouble, would it be possible to get a snapshot release for your type system directive PR, now that it's merged? https://github.com/walmartlabs/lacinia/pull/236

hlship18:10:23

0.31.0-SNAPSHOT-1 just uploaded

hlship18:10:51

I believe Apollo has an extension where you send up a series of GraphQL query documents that are executed serially; the first document can do mutations, the later ones can do queries. We don't support this currently, though it might be possible to accomplish this by injecting an interceptor.

domkm19:10:02

Batched queries? That's a good idea for @orestis. ApolloClient can batch queries (and mutations and maybe subscriptions) and send them to the server in a JSON array. I've used Lacinia (plain, not Pedestal) with this.