Skip to content

Instantly share code, notes, and snippets.

@praveenweb
Created May 23, 2019 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save praveenweb/3a81b3673211844067841c08b5e8fa17 to your computer and use it in GitHub Desktop.
Save praveenweb/3a81b3673211844067841c08b5e8fa17 to your computer and use it in GitHub Desktop.
GraphQL Subscriptions using Svelte
<script context="module">
import gql from 'graphql-tag';
import { client } from './apollo';
import { subscribe } from 'svelte-apollo';
const AUTHOR_LIST = gql`
subscription {
author(order_by: [{name: asc}]) {
name
}
}
`;
const authorsList = subscribe(client, { query: AUTHOR_LIST });
</script>
<ul>
{#await $authorsList}
<li>Loading...</li>
{:then result}
{#each result.data.author as author (author.id)}
<li>{author.name}</li>
{:else}
<li>No authors found</li>
{/each}
{:catch error}
<li>Error loading authors: {error}</li>
{/await}
</ul>
@EulerTourist
Copy link

What are you using for a backend?

@praveenweb
Copy link
Author

@sandalsoft
Copy link

This is very helpful, thank you @praveenweb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment