Skip to content
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

DB is not connected #1

Open
olsn opened this issue Jul 5, 2021 · 3 comments
Open

DB is not connected #1

olsn opened this issue Jul 5, 2021 · 3 comments

Comments

@olsn
Copy link

olsn commented Jul 5, 2021

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?

@olsn olsn closed this as completed Jul 5, 2021
@AWolf81
Copy link
Owner

AWolf81 commented Jul 6, 2021

@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
grafik

@AWolf81 AWolf81 reopened this Jul 6, 2021
@AWolf81
Copy link
Owner

AWolf81 commented Jul 9, 2021

@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.

Todos

  • Add Hasura migrations (at the moment, manually add the todo table)
  • Improve the styling and remove the Svelte/kit starter demo code.
  • Add more features to the todo app (delete todo & toggle status)
  • Revist the Svelte-apollo issue and check the generated code.
  • Review the CommonJS issue that we had here too (related svelte/kit issue #928)
  • Check the other implementation options
    • Apollo-lambda-server function
    • Polka & Postgraphile

@AWolf81
Copy link
Owner

AWolf81 commented Aug 1, 2021

OK, I've worked a bit on this (see main branch).

There are also two blog posts to the changes. You can find the links in this Tweet

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

No branches or pull requests

2 participants