-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Lazy inline queries #398
Comments
Yea, i agree that we probably want to be able to do this. I wonder if it would be enough to support having a floating <script>
import FooStore from '$houdini/stores/Foo'
graphql`
query Foo {
bar
}
`
// ....
</script> Thoughts? |
Another option is that we could kind of merge these a bit so that a reference to an inline query returns the store: <script>
const FooStore = graphql`
query Foo {
bar
}
`
</script> |
I like both approaches, the second one even a bit more. This way there you can immediately see the floating graphql tag has a purpose 😅 |
Actually, this 👇 <script>
import { graphql } from "$houdini";
graphql`
query Foo {
bar
}
`
</script> Is already generating the store But the preprocessor tries to do something with it (and it doesn't work). I see 2 ways: Bonus, the cool thing with |
i'm personally not a fan of the floating |
I see it as a great opportunity to mix styles (like #407). It's almost like a bug today that it's not already working like:
I have to say that the syntax with the import is also strange because you import something that you define inside the component. 😅 <script context="module">
import { GQL_Foo } from "$houdini";
export async load(event) {
await GQL_Foo.fetch({ event })
return {}
}
</script>
<script>
import { graphql } from "$houdini";
graphql`
query Foo {
bar
}
`
</script> We don't have to forget that the original question was about lazy. <script>
import { graphql, store } from "$houdini";
const myStoreNameFoo = store(graphql`
query Foo {
bar
}
`)
function randomAction() {
myStoreNameFoo.fetch()
}
</script> With |
hm maybe i'm missing something but i'm not sure what <script context="module" lang="ts">
// type is inferred from overloaded definitions of graphql
const store = graphql`
query MyQuery {
}
`
export async load(event) {
await store.fetch({ event })
return {}
}
</script>
<script>
$: browser && store.fetch()
</script>
{$store.value} |
Just a heads up, support for this will be added as part of the upcoming work to support the new KitQL api 👍 |
With the store api lazy queries are now easily possible by defining them in a separate file. But I would love to be able to define them inline.
My idea to implement this is:
We can probably detect whether the
query
call is part of a variable declaration or standalone, right? I.e. we can differentiate betweenand
If this is the case we could abort the preprocessor logic early to not execute the query in
load
or on mount.My thinking is that in the second case the user clearly does not intend to use the query data right now. So it seems logical to defer execution.
What do you think, @aivazis @jycouet?
The text was updated successfully, but these errors were encountered: