Replies: 5 comments 2 replies
-
I have tried to search around a bit more and have not found much for now. Thinking about how sveltekit allows loading of data in the load function and injecting the results as props to the page it would be amazing if the +page.js export function load({}) {
const client = ...;
const queryResult = client.query(QUERY, {...}).toPromise(); // no need to await
return {
queryResult
}
} +page.svelte <script>
import ...;
export let data;
$: gqlStore = queryStore({
client,
query: QUERY
initialData: data.queryResult // this line would maybe pre-populate the cache and prevent an initial network request from the client.
})
</script> |
Beta Was this translation helpful? Give feedback.
-
Thanks for your effort. |
Beta Was this translation helpful? Give feedback.
-
@Tiim I spent some time exploring the topic and hopefully find solution which fits best my needs What I expect
Let' look at my solution: +page.svelte
+page.ts
lib/urql.ts
The last piece is root layyout |
Beta Was this translation helpful? Give feedback.
-
Hi folks, I am experimenting with @farin solution but I am using +page.server.ts export const actions = {
login: async (event: RequestEvent) => {
const { request } = event;
const anyEvent = event as AnyPageLoadEvent;
const data = await request.formData();
const formData = Object.fromEntries(data);
const username = data.get('username');
const password = data.get('password');
if (!username || !password) {
return {
message: 'Username and password are required'
};
}
return {
success: true,
createQueryStore: await queryStoreFactory(FetchType.Mutation, anyEvent, (page) => ({
query: LoginDoc,
variables: { username: 'lackorol', password: 'lackorol' }
}))
};
}
}; I am getting I have tried createQueryStore: (
await queryStoreFactory(FetchType.Mutation, anyEvent, (page) => ({
query: LoginDoc,
variables: {username: 'lackorol', password: 'lackorol'}
}))
).toString() so stringify function with toString() and then in my +page.svelte <script lang="ts">
import Login from "../../components/auth/Login.svelte";
import { page } from "$app/stores";
export let form;
$: query = Function(form?.createQueryStore).call(null, $page);
</script> but query is undefined...any help or is my reasoning correct that I need to somehow pass function as string from server to client? |
Beta Was this translation helpful? Give feedback.
-
We are using svelte-kit's If a query is likely to be fast:
If a query is likely to be slow:
There may be a downside to this that hasn't become apparent yet... |
Beta Was this translation helpful? Give feedback.
-
Hi everyone
I'm trying to implement SSR with my SvelteKit project using urql. I found the SSR Exchange in the docs, but that does not really help me because I don't know where I could store the initial state.
As far as I understood, the queries must also execute during SSR for the exchange to collect the initial state, but in my experience sveltekit doesn't wait until the graphql queries are finished:
Has anyone found a working solution to server side rendering with urql and sveltekit?
Beta Was this translation helpful? Give feedback.
All reactions