For example,
const [query, setQuery] = createSignal(makeQuery(...args))
const data = createQuery(query, options)
createEffect(() => {
console.log(data())
})
// later
// disposes the previous query internally, makes a new one with the new query document.
// the effect will re-run with the new result eventually
setQuery(makeQuery(...otherArgs))
One reason for this is I find it too cumbersome to write query variables. So this is much easier in various cases:
function makeQuery(foo: string, bar: string) {
return gql`
query SomeQuery {
someStuff("${foo}", ${bar}) {
foo
}
}
`
}
For example,
One reason for this is I find it too cumbersome to write query variables. So this is much easier in various cases: