I am trying to implement graphql in sapper with apollo-boost and svelte-apollo by declaring a new ApolloClient in the _layout.svelte and setClient. Declaring the ApolloClient works just fine but when it comes to setClient it thows an:
Error: Function called outside component initialization
Here the script tag in my _layout.svelte
<script>
import Nav from '../components/Nav.svelte';
export let segment;
import fetch from 'node-fetch'
import ApolloClient from "apollo-boost";
import { setClient } from "svelte-apollo";
const client = new ApolloClient({
uri: "http://localhost:1337/graphql",
fetch: fetch,
onError: ({ networkError, graphQLErrors }) => {
console.log("graphQLErrors", graphQLErrors);
console.log("networkError", networkError);
},
})
setClient(client)
</script>