Skip to content

Error: Function called outside component initialization #61

Closed
@albertms10

Description

@albertms10

While setting up svelte-apollo with Sapper (#9), as there is no main App.svelte component, I tried to set the client in the _layout.svelte file.

<!-- _layout.svelte -->
<script lang="ts">
  import { setClient } from "svelte-apollo";
  import client from "../database/apollo";

  setClient(client);
</script>

However, I get the following error:

Uncaught (in promise) Error: Function called outside component initialization
    at get_current_component (index.mjs:629)
    at setContext (index.mjs:659)
    at setClient (svelte-apollo.es.js:14)
    at _layout.svelte:33
    at run (index.mjs:18)
    at Array.map (<anonymous>)
    at index.mjs:1390
    at flush (index.mjs:723)
    at init (index.mjs:1477)
    at new App (App.svelte:17)

Where should I set the client instead?

Edit

In previous versions of v0.3.0, the solution that #9 (comment) comments would work fine, but in v0.4.0 we must set the client with the proper method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions