Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

About GraphQL dynamic queries (questions for software selection) #580

Discussion options

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! 😄

You must be logged in to vote

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

Comment options

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

You must be logged in to vote
0 replies
Comment options

@landbed sounds like an interesting idea, but is it related to this issue?

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Answer selected by kyleconroy
Comment options

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.

You must be logged in to vote
2 replies
Comment options

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.

Comment options

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #580 on August 23, 2020 19:57.

AltStyle によって変換されたページ (->オリジナル) /