timhall / svelte-apollo

Svelte integration for Apollo GraphQL
MIT License
944 stars 69 forks source link

version 0.4.0 seems not work in hasura commutiy svelte apollo example #107

Closed windyboy closed 2 years ago

windyboy commented 2 years ago

The example code work fine with version 0.3.0. When I try to upgrade to 0.4.0 goes wrong.

error message: Uncaught (in promise) Invariant Violation: Expecting a parsed GraphQL document. Perhaps you need to wrap the query string in a "gql" tag?

giubaru commented 2 years ago

I'm using the 0.4.0 and it works fine for me, maybe you need to import gql from @apollo/client:

// App.svelte
<script>

  import { ApolloClient, InMemoryCache, gql  } from "@apollo/client";
  import { setClient, query  } from "svelte-apollo";

  // 1. Create an Apollo client and pass it to all child components
  //    (uses svelte's built-in context)
  const client = new ApolloClient({
    uri: "http://localhost:8000/graphql",
    cache: new InMemoryCache()
  });
  setClient(client);

  const GET_USER_DATA = gql`
    query {
      user(userId: 1) {
        username
      }
    }`

    const user = query(GET_USER_DATA, {
      // variables, fetchPolicy, errorPolicy, and others
    });

</script>
quasarchimaere commented 2 years ago

i also get the invariant violation, in my chrome network tab i see that the server is responding with the proper payload, could this mean that there is some issue with the InMemoryCache? (i upgraded svelte-apollo and apollo at the same time in order to get it out of the way, but so far this has not come to fruition)

quasarchimaere commented 2 years ago

i also get the invariant violation, in my chrome network tab i see that the server is responding with the proper payload, could this mean that there is some issue with the InMemoryCache? (i upgraded svelte-apollo and apollo at the same time in order to get it out of the way, but so far this has not come to fruition)

i am sorry, i just realized that this was due to a subcomponent that hasn't been refactored to the new query parameter list and therefore it did pass the client object into the part where the query would have gone