-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Use getClient internally and use result directly (not #await) #43
Comments
First off, thank you for this library. I've been able to successfully populate a list view query, and a login query using it, and I'm really happy to have this adapter allow me to use graphql / apollo in Svelte-land! 💯 So, I was about to create an issue apprehensively as I don't believe my issues are a bug but lack of docs perhaps--but the not #await part of this ticket makes me want to add my 2 cents... First off the proposal in OP for me doesn't matter too much and feels like it's just a difference between using a Promise vs. a Reactive Svelte variable which seems mostly idiomatic. I think using in a way that strays from the one main template based In fact, I was trying to get to the bottom of what's going on with Svelte and/or svelte-apollo with this dollar sign exactly, and why does everything stop working unless you "dereference" the result of your query or mutation result variable? I scoured the Svelte docs and it looks like there are two general uses of
https://svelte.dev/docs#3_$_marks_a_statement_as_reactive But this one uses
https://svelte.dev/docs#4_Prefix_stores_with_$_to_access_their_values I'm assuming that this must be how svelte-apollo is using this idiom and what gets returned upon something like a Reading the return type of All to say, I think some clarification on exactly what's happening with the dollar sign would be extremely helpful in the docs and help folks ramp up more quickly. I'm happy to help with a PR but only if I understand and can write the correct things :-) I think I should show also how I ultimately used this without using the template example as obviously not every graphql query maps to a result that should be displayed: export const LOGIN_USER = gql`
query($email: String!, $password: String!) {
login(email: $email, password: $password) {
id
}
}
`;
export const loginUser = (email, password) => query(
getClient(), { query: LOGIN_USER, variables: { email, password } }
); and then my form submit handler basically does: loginResults = loginUser(event.target.email.value, event.target.password.value);
$loginResults.then(results => {
if (results.data && results.data.login && results.data.login.id) {
alert('We got an ID so logged in: ' + results.data.login.id);
}
}); So, you see why I needed to figure out that I was dealing with this sort of Promise / store prefix thing in |
@timhall, what do you think if we change things to make it more like
@urql/svelte
?From this:
to this:
This can fix #19, #40 and #21.
Already started here: #42 but I need help.
The text was updated successfully, but these errors were encountered: