Comments (4)
Thanks for the update; been busy here. I'll try to digest what you have posted above.
from lacinia.
Could you elaborate on what you are using the variables for? Yes, we could expose how Lacinia internally tracks variables and values, but I prefer to do so carefully, in a way that allows us to change things in the future without breaking backwards compatibility. So if I had some insight into what questions you are trying to answer, that might yield a better, more stable solution.
from lacinia.
I'm working on a relational database to GraphQL API generator. For poll-based subscription optimization, the compiler has to group similar GraphQL queries into a single big SQL query to execute against the database. This requires knowing which variables are used (for the grouping), and which types they are (for appropriate SQL casts). Below is a sample:
subscription Test($name: String!) {
Customers(
where: {
fullName: { _in: [$name, "Test2"] }
id: { _neq: "47ae0cc8-9fd6-46b3-bdb8-e3bbc7c5adca" }
}
) {
id
fullName
createdAt
comm
updatedAt
metadata
addresses(
where: {
city: { _in: ["Test3", "Test4"] }
id: { _neq: "47ae0cc8-9fd6-46b3-bdb8-e3bbc7c5adca" }
}
) {
street1
city
countryCode
}
}
}
is currently grouped into this Postgres query:
WITH __subs AS (
SELECT
__subs_arr ->> 0 AS __sub_id,
__subs_arr ->> 1 AS name
FROM
JSON_ARRAY_ELEMENTS(
CAST('[["43f0282c-f9e9-4644-ac31-9dcdf5095530","jj"],["another sub id","$name value for this sub"]]' AS json)
) AS __subs_arr
)
SELECT
__sub_id AS sub_id,
__sub_res.result
FROM
__subs
LEFT JOIN LATERAL (
SELECT
COALESCE(
JSONB_AGG(__root_0.*),
'[]'
) AS result
FROM
(
SELECT
customer.id,
customer.full_name,
customer.created_at,
customer.comm,
customer.updated_at,
customer.metadata,
(
SELECT
COALESCE(
JSONB_AGG(__nest_1__0.*),
'[]'
)
FROM
(
SELECT
address.street_1,
address.city,
address.country_code
FROM
address
WHERE
(
city IN ('Test3', 'Test4')
)
AND (id <> '47ae0cc8-9fd6-46b3-bdb8-e3bbc7c5adca')
AND (
address.customer_id = customer.id
)
) AS __nest_1__0
) AS addresses
FROM
customer
WHERE
(
full_name IN (__subs.name, 'Test2')
)
AND (id <> '47ae0cc8-9fd6-46b3-bdb8-e3bbc7c5adca')
) AS __root_0
) AS __sub_res ON TRUE
I got to this with some hacks (i.e: using variables
data from request
context, which is without types and might be inaccurate). And this query works but as soon as we introduce some variables of non-primitive types, for example an "id" of UUID type:
Exception in thread "async-dispatch-8" org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid <> text
For the full solution, in the WITH
clause, we would need to cast values like so:
WITH __subs AS (
SELECT
__subs_arr ->> 0 AS __sub_id,
CAST(__subs_arr ->> 1 as uuid) AS id,
CAST(__subs_arr ->> 2 as text) AS name,
...
FROM
...
from lacinia.
This seems to be related to #430 in that both try to enrich parsed query context.
I'd like to have your inputs on how to best move forward @hlship
from lacinia.
Related Issues (20)
- Scalar type which returns vector HOT 4
- ::lacinia/null returned in unions instead of null HOT 1
- Apollo Federation Compatibility HOT 1
- Question: Is there a way to return JSON without a corresponding EDN definition? HOT 3
- Use of executor/selection in streamer functions HOT 1
- Document example of a raw JSON scalar
- cryptic errors when input is the wrong type
- Passing in variables wrapped in an array comes in as a double array HOT 5
- Support @defer and @stream directives
- Convert the keys of arguments and variables to kebab-case HOT 1
- Subscriptions may fail to stream data to the client
- Unbalanced braces in queries not causing parse-query to fail
- Tracing "validation" fields are always null
- Question: Query complexity and depth HOT 2
- Replace antlr4 deps with antlr4-runtime HOT 2
- Issue with merging fragments with list
- Adding support for deprecation on input fields
- Subscriptions do not maintain ordering HOT 3
- Make com.walmartlabs.lacinia/execute support read-only mode HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lacinia.