-
Notifications
You must be signed in to change notification settings - Fork 923
About GraphQL dynamic queries (questions for software selection) #580
-
Sorry if I open this issue, @kyleconroy, it is mostly a question but certain words that I will use can be "searched" and anyone can benefit from your answer and the discussion that could follow.
PREAMBLE
I discovered this project a few hours ago.
After trying everything in Go (go-pg, sqlx, sqlboiler, gorm, kallax and others) I believe your project is simply WONDERFUL!
But before jumping into it headlong I would like to understand if I can really achieve what I have in mind.
My project has many tables (around 100 today).
90% of the operations are simple CRUD.
For all tables I have the same (or very similar) .sql file, like this:
-- name: GetPlayer :one SELECT * FROM players WHERE id = $1 LIMIT 1; -- name: ListPlayers :many SELECT * FROM players ORDER BY id desc; -- name: CreatePlayer :one INSERT INTO players ( account_id, team_id, topology ) VALUES ($1, $2, $3) RETURNING *; -- name: UpdatePlayer :one UPDATE players SET account_id = $2, team_id = $3, topology = $4 WHERE id = $1 RETURNING *; -- name: DeletePlayer :one DELETE FROM players WHERE id = $1 RETURNING *;
And so far so good. Everything works very well (again, congratulations!).
MY REAL FEAR
For this project I also need to create GraphQL APIs.
Almost every table must be able to be filtered on all or some specific columns.
And the goal is to have a dynamic and flexible query like:
export const LIST_PLAYERS = gql` query ListPlayers($first: Int, $skip: Int, $orderBy: PlayerOrderByInput) { players(first: $first, skip: $skip, orderBy: $orderBy) { id created_at ... } } `
or
query { products(limit: 5, where: { price: { gt: 12 } }) { id name ... } purchases( limit: 10 order_by: { created_at: desc } where: { user_id: { eq: $user_id } } ) { id created_at ... } }
Using also these logical operators: https://supergraph.dev/docs/graphql#logical-operators.
(SuperGraph is an amazing project!)
QUESTION
Is there any way to create such a dynamic query?
I read this issue and got a little scared.
Thanks for your effort and your patience.
If sqlc
can solve my problem there will be sponsorship: these gold projects must be financed! 😄
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 5
If sqlc can solve my problem there will be sponsorship: these gold projects must be financed! 😄
Sadly, sqlc can't currently solve your problem. As outlined in #364, dynamic query support is at odds with compiling individual queries. You can write queries that filter on different parameters but those queries may perform poorly in production. I hope to have a better answer in the future, but for now there isn't one.
Replies: 4 comments 2 replies
-
how about auto generate basic build-in CRUD queries and functions? I know that's easy but really don't want to copy and paste CRUD sql. @kyleconroy
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
@landbed sounds like an interesting idea, but is it related to this issue?
Beta Was this translation helpful? Give feedback.
All reactions
-
If sqlc can solve my problem there will be sponsorship: these gold projects must be financed! 😄
Sadly, sqlc can't currently solve your problem. As outlined in #364, dynamic query support is at odds with compiling individual queries. You can write queries that filter on different parameters but those queries may perform poorly in production. I hope to have a better answer in the future, but for now there isn't one.
Beta Was this translation helpful? Give feedback.
All reactions
-
Just gonna say this is kind of a backwards way to go about sponsorship. You should be willing to pay to get the features added that you need.
Beta Was this translation helpful? Give feedback.
All reactions
-
Very willing to implement features for paid sponsors. However, even if @frederikhors became a sponsor, it's not clear how we'd implement dynamic queries. There are a few different ideas in #364, but I don't think any of them are fleshed out enough to implement.
Beta Was this translation helpful? Give feedback.
All reactions
-
Sure, I was just pointing out the attitude "I will sponsor this project if and only if it can implement the solution to my problem" is backwards, sponsorship will help build out the features that people need!
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 2