I’m trying do develope a VUE JS app, and would like to use DGraph for my data. In earlier projects I used NEO4J and Express/Apollo for communication between my client and the NEO4J database.
I tried to use the dgraph-js/grpc library directly in VUE, but get errors indicating that my code doing DGraph stuff should run in another environment (not the web-browser).
I suspect that I have to establish a nodejs server component using e.g. Express, and then have my client communicate with the Express server, and then have the Express server communicate with the DGraph server.
Is there any best practices on how to develop a SPA using Vue, Angular, React etc. and DGraph as datastore.
I’m considering to use the express server as a route, accepting my graphql+ queries and just push them forward to the DGraph server, and the same with the response… Is there any reason for why I should avoid such an approach?
If there is an example available on github, that could point me in the correct direction that would be most appreciated.
Any guidance on how to best communicate between a SPA client and a DGraph server is most welcome.
If this request should have been posted in a different forum or thread, please accept my apologies…
It would be safer for you to create an API with Express and not link your project directly to Dgraph. Creating a NodeJS server (as API/REST) would be more interesting for better control of what is being inserted.
I am building a app with DGraph, (micro / express & apollo), and Angular on AWS with Lambda all in typescript. So if you have any specific questions I can try to help out, or if you find any best practices elsewhere online I would be keen to hear about them.
I came to the same conclusion as @MichelDiz that you really want some GraphQL layer in front of your DGraph db.
Reasons
You can connect GraphQL to multiple database
Some actions may require other services - I email uses on some actions.
Validating inputs
Protecting your db from malicious actors - Maybe the most important one
That said often I find myself writing the same query and just piping it through to DGraph, I feel like the eventual solution here is to use something like this:
So you can get a list of the graphql query fields and pipe them trough to a specific DGraph query.
Great - thanks.
I have now a working VUEJS app working that used the dgraph-http-js library that talks directly with the dgraph database.
I have used the graphQL apollo library and used that to talk to NEO4J, where I “replace” all graphql queries with CYPHER queries. I quess I could the similar with DGRAPH, where I have my graphQL query in the client, and do a graphQL+ in the express server.
I agree that the best would be to have a separate express “server” that sits between my VUE client and the DGRAPH server. To get better security until DGRAPH have authentication and ACL implemented.
I will post a simple demo on GitHUb when I have this sorted out
@erlendoverby Interested to learn if you got this working and maybe you’d be willing to share what code you have. Now that dgraph has native GraphQL, might be a good starting place.
Your approach of using an Express server as a middleware between your Vue.js SPA and the DGraph server is indeed the recommended practice. Since dgraph-js (gRPC client) is not designed to run in the browser, a Node.js backend is necessary to handle database interactions. You can set up an Express server with Apollo Server or another GraphQL middleware to act as a relay for GraphQL± queries. This setup ensures security, allows for authentication/authorization handling, and prevents exposing your DGraph server directly to the frontend. If you’re looking for an example, you might check out DGraph’s official examples on GitHub. Additionally, consider using dgraph-js-http if you want to avoid a Node.js backend, but note that it has limitations compared to the gRPC client.