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. PREAMBLEI 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 FEARFor 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!) QUESTIONIs 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 |
Beta Was this translation helpful? Give feedback.
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.
-
@landbed sounds like an interesting idea, but is it related to this issue? |
Beta Was this translation helpful? Give feedback.
-
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.
-
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.
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.