Open olsn opened 3 years ago
@olsn yes, you're right the DB is not connected yet. It's on my to-do list.
There are some ways to create a backend service to connect Svelte to the database. Initially, I wanted to create an Adonisjs backend but this seems way too complicated (proxy, data fetching, ...)
I think an easy way is to use Hasura so the DB connection from Svelte is pretty straightforward with Apollo Graphql. (There is also a nice console in Hasura to test Graphql queries & check the Postgres database)
I've worked on the Hasura setup but it's not ready yet. The docker setup with Hasura is working. I just need to fix an issue related to Apollo (getting TypeError: this.client.send is not a function
from subscriptions-transport-ws
).
Once the demo todo app is working, I think I'll create a blog post for it.
Other options to connect to the DB (I haven't tested them):
Update 08.07.2021:
I'm still trying to fix the import of @apollo/client/core
. The problem node adapter and Sveltekit needs the Commonjs import but using @apollo/client/core/core.cjs.js
throws the following error (during dev server):
ReferenceError: exports is not defined
at eval (/node_modules/@apollo/client/core/core.cjs.js:3:23)
at instantiateModule (C:\Users\alexander\GitHub\my_docker_app\app\node_modules\@sveltejs\kit\node_modules\vite\dist\node\chunks\dep-cc49d7be.js:72639:166)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
I've pushed my current work into branch backend-graphql
(with the bug mentioned above).
Database migrations not added - manually creating a todo table with id (primary key, auto int), title (string) & completed (boolean) required on localhost:8080
@olsn OK, I've made some progress in the branch backend-graphql.
Todo app is working in dev mode and the build is also working. The Docker setup works but needs some improvements (see todos below).
There where some issues with @apollo/client
and svelte-apollo
. I'll review it and add some more details to it.
The main issue was the error Function called outside component initialization
as mentioned in this issue #97 / svelte-apollo.
After removing svelte-apollo
it is working. I'm using setContext
/ getContext
like Svelte-Apollo
and the demo works with @apollo/client
directly.
Not sure how to get it to work with svelte-apollo
- tried a lot but nothing was working.
Svelte-apollo
issue and check the generated code.CommonJS
issue that we had here too (related svelte/kit issue #928)
Maybe I'm overlooking something, but it seems your DB is not really connected in the Svelte-App. That's actually the most difficult part (WITHOUT hardcoding the credentials!) - do you have a solution for that already?