Skip to content

Files

Latest commit

Oct 6, 2020
90a2c2d · Oct 6, 2020

History

History
107 lines (76 loc) · 3.14 KB

README.md

File metadata and controls

107 lines (76 loc) · 3.14 KB

@svelkit/graphql

A lightweight GraphQL client for svelte

License Latest Release View changelog Bundle Size

What?

Use GraphQL APIs in svelte the svelte way. Either as readable store or using promises.

Why?

Existing solutions (graphql-svelte, @urql/svelte, and others) didn't provide the API we were looking for, features we would not need or are to heavy.

This solutions focuses on a native svelte API using svelte/store.

Installation

npm install @svelkit/graphql

And then import it:

// using es modules
import { useQuery, gql } from '@svelkit/graphql'

// common.js
const { useQuery, gql } = require('@svelkit/graphql')

Alternatively use UNPKG or jsDelivr packages.

Hotlinking from unpkg: (no build tool needed!)

import { useQuery, gql } from 'https://unpkg.com/@svelkit/graphql?module'

Usage

<script>
  import { initGraphQLClient, useQuery, gql } from '@svelkit/graphql'

  initGraphQLClient({ uri: 'https://swapi.graph.cool/' })

  const films = useQuery(gql`
    query AllFilms {
      allFilms {
        id
        title
        releaseDate
      }
    }
  `)
</script>

{#if $films.fetching} Loading .. {:else if $films.error} Ups... {$films.error.message} {:else}
<ol>
  {#each $films.data.allFilms as film (film.id)}
  <li>{film.title} - {file.releaseDate}</li>
  {/each}
</ol>
{/if}

Features

Polyfills

  • URL
  • URL#searchParams
  • Object.entries
  • fetch
  • globalThis

License

svelkit is open source software licensed as MIT.