timhall / svelte-apollo

Svelte integration for Apollo GraphQL
MIT License
945 stars 67 forks source link

result not Found #108

Closed bobwatcherx closed 2 years ago

bobwatcherx commented 2 years ago

my file svelte

<script>
    import { ApolloClient,gql } from "@apollo/client";
  import { setClient,query } from "svelte-apollo";
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createHttpLink } from 'apollo-link-http';
   const client = new ApolloClient({
  link: createHttpLink({ uri: 'https://graphql.contentful.com/content/v1/spaces/hsb6hcp4u643/explore?access_token=-q8KutJny9G02QUV2oMOL9lsei3_fvu7BJ-MEs68L0U' }),
cache: new InMemoryCache()
  });
     setClient(client);
    const GETDATA = gql`
{
  modelSekolahCollection{
    items{
      id
      nama
      gambar {
        title
        description
        contentType
        fileName
        size
        url
        width
        height
      }
    }
  }
}

    `
const book = query(GETDATA)
console.log(book)
</script>

My CONSOLE: {subscribe: ƒ, fetchMore: ƒ, getCurrentResult: ƒ, getLastError: ƒ, getLastResult: ƒ, …}

giubaru commented 2 years ago

Hi, const book = query(GETDATA) returns a storage with promises within, you should access the result using $ as show you below:

{#if $books.loading}
  Loading...
{:else if $books.error}
  Error: {$books.error.message}
{:else}
  {#each $books.data.books as book}
    {book.title} by {book.author.name}
  {/each}
{/if}