graphql-engine/community/sample-apps/svelte-apollo
Samir Talwar d9afcc1857 Upgrade all package-lock.json files to the v2 format.
NPM v7 uses a new (backwards-compatible) lockfile format. This upgrades all our various _package-lock.json_ files to use the new format.

It's much more verbose so that NPM can be a lot faster.

I figured it was cleaner to do this once in a separate PR rather than upgrading them in combination with adding or upgrading a new dependency.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5869
GitOrigin-RevId: 322fb63b96e2d873a4a3cc05fa6c7afa414716ce
2022-09-28 08:15:29 +00:00
..
public add github workflow to compress new images in PRs 2021-03-10 20:55:02 +00:00
src community: svelte-apollo: fix connectionParams (close #2769) (#2893) 2019-09-17 13:14:10 +05:30
.gitignore sample-apps: add svelte 3 graphql app (#2256) 2019-05-23 17:00:16 +05:30
now.json sample-apps: add svelte 3 graphql app (#2256) 2019-05-23 17:00:16 +05:30
package-lock.json Upgrade all package-lock.json files to the v2 format. 2022-09-28 08:15:29 +00:00
package.json sample-apps: add svelte 3 graphql app (#2256) 2019-05-23 17:00:16 +05:30
README.md readme: use cloud signup endpoint for "Deploy to Hasura" CTA 2021-08-19 07:03:05 +00:00
rollup.config.js sample-apps: add svelte 3 graphql app (#2256) 2019-05-23 17:00:16 +05:30

svelte-graphql-app

A sample Svelte 3 app to demonstrate usage of GraphQL Queries, Mutations and Subscriptions with svelte-apollo, Hasura Cloud and Postgres as database. Forked from the standard svelte template

Edit svelte-graphql

Create new Hasura Cloud project

  • Deploy GraphQL Engine on Hasura Cloud and setup PostgreSQL via Heroku:

    Deploy to Hasura Cloud

  • Get the app URL (something like https://<my-project-name>.hasura.app)

  • Create author table:

    Open your Hasura Cloud project's console: visit https://<my-project-name>.hasura.app on a browser
    Navigate to Data section in the top nav bar and create a table as follows:

    Create author table

  • Insert sample data into author table:

    Insert data into author table

    Verify if the row is inserted successfully

    Insert data into author table

  • Similarly, create an article table with the following data model: table: article columns: id, title, content, author_id (foreign key to author table's id) and created_at

    Create foreign key for author_id column to author's id

  • Now create a relationship from article table to author table by going to the Relationships tab.

  • Clone this repo:

    git clone https://github.com/hasura/graphql-engine
    cd graphql-engine/community/sample-apps/svelte-apollo
    

Setup App

Install the dependencies...

npm install
  • Open src/apollo.js and configure Hasura's GraphQL Endpoint as follows:

  const wsLink = new WebSocketLink({
    uri: "ws://localhost:8080/v1/graphql",
    options: {
      reconnect: true,
      lazy: true
    },
    connectionParams: () => {
      return { headers: getHeaders() };
    },
  });

  const httpLink = new HttpLink({
    uri: "http://localhost:8080/v1/graphql",
    headers: getHeaders()
  });

Replace the uri argument with your Hasura GraphQL Endpoint (something like https://<my-project-name>.hasura.app/v1/graphql) for both wsLink and httpLink

Start Rollup:

npm run dev

Navigate to localhost:5000. You should see your app running. Edit a component file in src, save it, and reload the page to see your changes.

Deploying to the web

With now

Install now if you haven't already:

npm install -g now

Then, from within your project folder:

now

This will deploy the app on Now 2.0 Platform and you have the Svetle app running live :)