Skip to content
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

Support +page.server.gql #762

Open
AlecAivazis opened this issue Dec 14, 2022 · 4 comments
Open

Support +page.server.gql #762

AlecAivazis opened this issue Dec 14, 2022 · 4 comments
Labels
Enhancement A new feature or improvement to Houdini's public API 🍎 Low Hanging Fruit SvelteKit Issues related to the SvelteKit integration

Comments

@AlecAivazis
Copy link
Collaborator

AlecAivazis commented Dec 14, 2022

Describe the feature

Would be very interesting to automatically convert a +page.server.gql file into a load function that gets created inside of a .server.js file

edit: Since there are a lot of 👍 on this issue I should probably mention that this is relatively straight forward, even if it sounds a bit daunting. If someone wants to take this on, please reach out to me on Discord

@xmlking
Copy link

xmlking commented Dec 20, 2022

and the form actions in +page.server.gql

@jycouet
Copy link
Contributor

jycouet commented Dec 20, 2022

Actions are more for mutation no?
Could you describe a bit more the usecase, I'm curious 👀?

@xmlking
Copy link

xmlking commented Dec 20, 2022

you can see here https://github.com/xmlking/svelte-starter-kit/tree/main/src/routes/(app)/dashboard/policies/%5Bid%5D
in +page.server.ts I am using both load and actions
load is used to populate the edit form. and actions are used when they click Save button.

I want to replace this +page.server.ts file with +page.server.gql

@jycouet
Copy link
Contributor

jycouet commented Dec 20, 2022

I would see +page.server.gql handling the load function.
To keep in mind:

Today you have one action called save and inside you

  • Check if the user is logged
  • Decide (with some logic) if it's a create or an update.
  • you have to get form data to pass them as variables request.formData() (adding some logic like formData.id = crypto.randomUUID();, ...)
  • Then you handle errors & "not found" custom code.

All this too say that you have some custom code to write somewhere (your own business logic).


I see that you are using row "gql queries" and "await fetch",

Did you try doing something like (having GetByID.gql file beside your +page.server.ts):

import { GetByIDStore } from '$houdini'

export async function load(event) {
	const gql = new GetByIDStore()
	const { data } = await gql.fetch({ event })

// Your custom logic

	return { data }
}

I just throw this here as a memo, maybe:

  • +page.server.gql => can be use in combination with _houdini_load of +page.server.ts
  • +page.create.server.gql => can be use in combination with _houdini_action_create of +page.server.ts
  • +page.update.server.gql => can be use in combination with _houdini_action_update of +page.server.ts

(I don't know how it would look like)


EDIT
Actually, if you create a file:
mutation.create.server.gql, you can already import the mutation store and trigger the mutation.
You can also do it inline like

const uncheckItem = graphql(`
		mutation UncheckItem($id: ID!) {
			uncheckItem(item: $id) {
				item {
					id
					completed
				}
			}
		}
	`)
uncheckItem.mutate({id: '123'})

@AlecAivazis AlecAivazis added the Enhancement A new feature or improvement to Houdini's public API label Dec 23, 2022
@AlecAivazis AlecAivazis added the SvelteKit Issues related to the SvelteKit integration label Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A new feature or improvement to Houdini's public API 🍎 Low Hanging Fruit SvelteKit Issues related to the SvelteKit integration
Projects
None yet
Development

No branches or pull requests

3 participants