question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Processing GraphQL input variables.

See original GitHub issue

GraphQL has input object types defined in the schema. This means that one could look up what they are and use an variable of one of those types, such as InsertUser or even FilterUser or OrderUser. The first one of these examples mostly contains data, but if User has links it may also contain command for filtering objects to be linked as opposed to raw data. The other two are just commands abstracted away into input objects.

We use these commands from input objects to compile the query, so these “variables” aren’t really query parameters, they may just be the query itself. E.g. OrderUser variable could be passed as {"order": {"name": {"dir": "ASC"}}}. The final query will have an ORDER BY .name ASC clause, but won’t have any parameters.

However, the more likely application of passing complex data to a GraphQL query is some kind of bulk insert scenario, where the data is an array of InsertUser objects for example. In theory if we restrict the elements to be homogeneous in structure (such that they all fit the same query shape) it would be possible to generate a FOR ... INSERT query that uses JSON functions to decompose the original JSON input blob into a bulk insert.

The bottom line is that the current implementation is limited to dealing with only scalar input variables and doesn’t have a way of dealing with the above scenarios. In order to make it fully compatible with them 2 changes need to happen:

  1. There logic that interprets “commands” needs to be abstracted in a way that it works both on actual GraphQL literals and variable values.
  2. In case of bulk inserts an additional check needs to be performed to validate that the insert shape is the same across the entire bulk operation.

This is related to #1229

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
1st1commented, Feb 20, 2020

I realize that commands in variables present problems with caching

Not only that, they are essentially a way to change a query substantially – add extra filters, nested inserts, etc. I guess for this kind of functionality we’ll have forms API some day, but for now we should keep our GraphQL simple.

1reaction
elpranscommented, Feb 20, 2020

I’m also leaning to restrict variables to data only (i.e no commands).

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL quick tip: How to pass variables in GraphiQL
I use passing variables using GraphQL playground all the time. We can easily copy and paste the code to our *.graphql files and...
Read more >
Tutorial: GraphQL Input Types and Custom Resolvers
The best practice in GraphQL is to use query variables for arguments ( $channelId for id in this case). The GraphQL spec requires...
Read more >
Passing Arguments - GraphQL
Using $dice and $sides as variables in GraphQL means we don't have to worry about escaping on the client side. With basic types...
Read more >
GraphQL quick tip: How to pass variables in GraphiQL - Medium
I use passing variables using GraphQL playground all the time. We can easily copy and paste the code to our *.graphql files and...
Read more >
How to Use GraphQL Operation Names and Variables - Shopify
Just like in that query variables pane of GraphiQL, I'm specifying an object of key ID and then the actual string that corresponds...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found