Fork me on GitHub
#graphql
<
2020-02-11
>
Joe Corneli16:02:16

Hi folks, I am just getting used to Lacinia and GraphQL, with a basic question that I hope you can help me with. I refer to the critique here: https://github.com/vvvvalvalval/d2q#lacinia-and-graphql

Joe Corneli16:02:38

They say "queries are difficult to compose and transform, which greatly hurts the programmability of GraphQL".

Joe Corneli16:02:01

I wasn't able to figure out how to compose queries at all, actually, and I wonder if someone could give me some pointers.

Joe Corneli16:02:12

What I understand from the documentation of Lacinia is that you can give it a list of queries, but there's no guarantee about execution order.

Joe Corneli17:02:00

So, the specific use case I have in mind: I want to do something akin to a SELECT * FROM tablename_ -- in fact, that's basically how the query is implemented.

Joe Corneli17:02:33

But then I would like to do further processing of the id field that returned from that query.

Joe Corneli17:02:25

The docs say that mutations do have a guaranteed execution order, but it seems to me that these are usually used to update the database, rather than to update the results of a previous query.

Joe Corneli17:02:42

I wonder, is this ever done? Using a mutation to update a query that has just run, I mean. So, in my case I could take the id field and expand the query results (e.g., by testing whether that id has other properties).

Joe Corneli17:02:44

The alternative is to change the SELECT statement in the database backend, but this seems like a fairly hacky solution.

hiredman17:02:21

graphql is very much not sql, where as sql has a sort of transitive closure where a sql query can kind of be the input to another sql query, that isn't really the way graphql is structured, and graphql is really a facade that ties together different bits into a uniform model for clients, so it is entirely possible that yeah, based on slightly different queries from clients you might change which sql query you run, or maybe even change which datastore you consult

hiredman17:02:53

graphql mutations are analogous to like an update, insert, or delete in sql, where as queries are like a select, so talking about applying mutations to results of queries makes about as much sense as talking about applying an update to the result of a select (none)

hiredman18:02:32

if you look at something like https://www.howtographql.com/graphql-js/8-filtering-pagination-and-sorting/ the way it filters things is by passing the filter into the resolver, and if a filter is passed in the resolver applies it when resolving

hiredman18:02:26

re: ordering, resolvers are run from the root to the leaves, so the resolvers higher in the graph will run first and can get information in bulk and pass it down to the leaves