-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support GraphQL query language #218
Comments
Seems 2 can be implemented in a single query http://bender.io/2013/09/22/returning-hierarchical-data-in-a-single-sql-query/ (just wow, PostgreSQL is powerfull) |
Ugh... please no. Adding a translation layer for some other query language sounds like a wonderful spot for bugs to collect. |
Not doing something just because there may be bugs there does not seem like a logical thing. Please read what GraphQL is about before dismissing the idea. And even if someone does not like graphql, postgrest currently dose not support requesting tree like data (or even selecting only the columns you need), and until it can support that it's not going to be used in production. |
Sure it supports tree-like data; pass it out as a JSON object if you like. Furthermore I do use it in production, so your point there holds no water. Obviously bugs can work their way in anywhere; however, in this case in particular, you are asking for a translation layer that converts between two separate sets of abstractions. It would be far better to write a separate system which exposes a PostgreSQL server as GraphQL, rather than bifurcating the code to support it. I've written this same API server several times in other languages; you do not want mixed abstractions here; it will only befuddle reasoning about the way it operates. The interface here should solely be a clean, clear interface into a limited subset of SQL necessary for traversing over result sets. For everything more complicated, write a view. The API server needn't have its own detailed query language for that very reason. |
Or otherwise why don't we throw in "odata" and every other API standard? |
You said "it supports tree-like data", can you give an example of how i would request that (i might've completely missed that)? GraphQL is "a limited subset of SQL necessary for traversing over result sets" :), there's no joining or aggregating going on there |
It supports any data which can come out of a view. As far as writing tree traversal in SQL, there's the "with recursive" mechanism. Or if you're just talking about doing a simple join, there's that too. You shouldn't try to use this thing to be what it isn't, a sort of object-store. This is a relational database, and a powerful one at that, and you should leverage the full power of SQL here. To the extent that you try to put an additional layer between yourself and the functionality of the database, you will only limit yourself to the subset of functionality which the intermediary layer supports. |
Oh, also... check out json_agg. That I think along with an inner join solves precisely your problem. |
What i understand from your response is that i should create another view to get the data in the format i described, is that correct? If that is the case then i do not agree with this approach. You are assuming that i am the only user of my API and whenever i need some new type of data (new shape) i can just create a new view. Yes i can use the views to present some complicated query/join as a flat table but if i have 2 tables that have a "one to many" relation, i should not have to create a special view just to get the data from both of them at the same time. |
There's no flame war; asking for a big wad o' complexity should involve vigorous debate. |
@ruslantalpa thanks for your detailed suggestion. Right now I think the proposal is too complicated. There is a lot of work remaining to get the basic things working properly first. I'd suggest creating views in your db to provide customized table results. In your example you could join tasks projects and clients. Happy to discuss your specific scenario in more detail and how it could be implemented with existing postgrest features. |
I think it would be useful to extend PostgREST to understand GraphQL (https://facebook.github.io/react/blog/2015/05/01/graphql-introduction.html)
Example of GraphQL (my understanding of it, the specs are still evolving)
This type of query allows big flexibility in extracting/filtering the data you need, in the shape that you want.
My understanding is that PostgREST currently supports only something like this
Currently, to get back the data describe in the first example, it would mean to make 3 http request, in 2 stages (get the list of the projects, get the tasks and the clients in parallel based on the project ids).
Things that need to be implemented to achieve this:
Haskell, so please ignore the example it it's stupid :)
The text was updated successfully, but these errors were encountered: