graphql

2020-02-11T16:57:16.057Z

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

2020-02-11T16:57:38.057700Z

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

2020-02-11T16:58:01.058300Z

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

2020-02-11T16:59:12.059200Z

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.

2020-02-11T17:00:00.060200Z

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.

2020-02-11T17:00:33.060800Z

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

2020-02-11T17:01:25.061700Z

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.

2020-02-11T17:03:42.064100Z

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).

2020-02-11T17:04:44.065200Z

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

2020-02-11T17:57:21.068600Z

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

2020-02-11T17:58:53.070300Z

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)

2020-02-11T18:01:32.071400Z

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

2020-02-11T18:03:26.072700Z

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