-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
URQL for mutations? #106
Comments
URQL also has Node bindings. Would it make sense to use those bindings in import { createClient } from '@urql/svelte';
import * as gql from "$lib/generated/graphql"
interface UpdateBuildingFormData {
data: gql.BuildingUpdateInput,
where: gql.BuildingWhereUniqueInput,
}
const client = createClient({
url: "http://localhost:4000/graphql"
})
/** @type {import('./$types').Actions} */
export const actions = {
// Take form data and process GraphQL mutation.
default: async ({ cookies, request, url }: any) => {
let output;
let data = await request.formData()
client.mutation(gql.UpdateBuildingDocument, {data: {street_address_1: {set: "hello"}}, where: {id: "eb52a6bb-fa8f-4994-8fbe-1dd76e4369d7"}})
.toPromise()
.then((result) => {
console.log("result: ", result)
})
}
} |
🤔 Maybe you could check if the client is already instantiated before creating a new one, or use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! This example repo is helpful in understanding how to execute GraphQL queries using urql in a Sveltekit project, but for the life of me I can't find an example of executing GraphQL mutations. It seems like the @urql/svelte library assumes you'll only be executing client-side mutations instead of server-side (i.e. within +page.server.js files). If you want to submit a form, for example, Sveltekit highly recommends Form Actions, which require using *.server.js files. However, server files don't have access to Context, which urql mutations use; I get an error when calling
getContextClient
from @urql/svelte within a +page.server.js, which makes sense.Any ideas on using urql mutationStore in server files? Am I missing something?
The text was updated successfully, but these errors were encountered: