0

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>
Silex
  • 31
  • 3

1 Answers1

1

I found the answer myself, at least svelte-apollo needs to be an devDependencie. I made apollo-boost and graphql devDependencies, too, but I dont know if its necessary

Silex
  • 31
  • 3