@svelkit/graphql
TypeScript icon, indicating that this package has built-in type declarations

0.6.3 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @svelkit/graphql

Weekly Downloads

183

Version

0.6.3

License

MIT

Unpacked Size

157 kB

Total Files

16

Last publish

Collaborators

  • sastan