ponzu-cms / ponzu

Headless CMS with automatic JSON API. Featuring auto-HTTPS from Let's Encrypt, HTTP/2 Server Push, and flexible server framework written in Go.
https://docs.ponzu-cms.org
BSD 3-Clause "New" or "Revised" License
5.68k stars 387 forks source link

Live queries / graphql. #273

Open ghost opened 6 years ago

ghost commented 6 years ago

I need live queries.

Firstly I would like to get a notification of the crud event on a boltdb bucket.

Secondly I would like to then rerun the query and push the delta to the front end.

The golang project for graphql has the 2nd part is place using a data loader and cache.

Ponzu if I am not mistaken now has events on bucket change.

So it's all in place to allow Ponzu to support graphql.

It might be easy to gen the graphql schema from Ponzu and allow uses to have a igraphql like query web interface. Then they can augment the graphql schema and build up their queries.

It's not all plain sailing but I think it's very doable.

To be clear, this does not change the ponzu Ali or break backwards compatibility. It's a layer on top only.

This also allows different data repositories to be used with ponzu too. For example a file store using minio. A git repo even can be a repository. Anything essentially.

Some may say that it should be a separate project too. Fair enough. My arguement is that combining the graphql with ponzu is a very powerful combo. It really sets up people to build ponzu projects where different ponzu projects are responsible single for different things in a Microservice style. This would help ponzu modules to be shared by users. Also it does not mean your forced into containers at all. Because it's golang all the way down you can still run everything in a service or process.

Anyway I guess that's enough pitching :)

What about comments on this ? Maybe others have e a need for this for react or whatever. Maybe others are already doing this but using a different approach ?

https://gqlgen.com/getting-started/

I can add some examples if needed to show how easy it can be.

nilslice commented 6 years ago

@gedw99 Hey, thanks for sharing some ideas! Lots to unpack here, so I'll address as much as possible, and likey part-by-part. If you do have some code / working examples I could run please do share. I'm interested to see what you have in mind.

nilslice commented 6 years ago

Live queries

Without considering much about graphql, I thought a bit about how something could be added to broadcast the item.Hookable interface methods (i.e. BeforeAdminDelete, or AfterAPICreate, etc.) across content types, or even out to something outside of Ponzu.

I just put together this package to see if it could be a building block towards something that propagates the CMS actions creates by API- or Admin-driven events. I like this concept, and think it could be used for a number of different "live data" implementations. https://github.com/ponzu-cms/live

Let me know if it's heading in the right direction to address the need you describe.. I'm not very familiar with grpahql, so it's quite possible that I've misunderstood something!

ghost commented 6 years ago

hey @nilslice. Thats awsome. I think that proves that layer well.

I think its going to be very easy to get a graphql layer on top due to Ponzu having this architectural aspect.

I was thinking about where to code gen from. As far as i know Ponzu forces you to use the CLI to make a type right ? Now the types are discoverable right, so we can then expose the types into a web IDE designed for Graphql and as the user types they can get confirmation that the graphql schema is valid.

So non graphql users can just use Ponzu the way they are used to, but if then want to compose a combination of ponzu "services" they can just open the IDE and make a graphql schema. Then code gen off the graphql schema and we are done.

Thats where i am on this currently. Would appreciate feedback / validation on the approach so i can start on the graphql layer.

Solander commented 4 years ago

I agree with ghost that this would be a good idea. It would optimize how to get the data from Ponzu. If I for instance want all the books and the author's name in one query and in the next want one specific author with all his/hers books. With GraphQL I would be able to change the query on the frontend and Ponzu would return exactly what I need and nothing more. This is possible with building different endpoints on the backend, but that approach would also mean that I would need to do a lot of work for each change, when a GraphQL implementation would take care of all the different cases.

olliephillips commented 4 years ago

Hey @solander. Thanks for kicking off this discussion again. GraphQL is everywhere now it would be great to support - could you lead some development on this front?

Solander commented 4 years ago

@olliephillips I've just started looking into how to manage this for Ponzu. Found a way to do it but trying to determine if it's a good way or not. If I find something I'm happy with, maybe I will try to make it into a fork of Ponzu.

olliephillips commented 4 years ago

Great news, thanks for updating. I've limited experience with GraphQL myself @Solander but do post here if you want to kick your ideas about. This is an active repository and there will be people that can help out with GraphQL.

Solander commented 4 years ago

Great! I will see when I have time to experiment some more!

txbrown commented 4 years ago

Any updates on this issue? I am also very keen on having GQL support and happy to help where I can. Cheers.

Solander commented 4 years ago

I wish I could say that I have finished this, but time has been limited so I haven't done anything other than researching on how to do it. Haven't really decided which approach I should aim for.