Replies: 6 comments 7 replies
-
I have a question! The <script>
import gql from 'graphql-tag';
import { query } from '@urql/svelte';
// returns the operation store and runs the query in 1 hit
const todos = query(gql`
query ($first: Int!, $skip: Int) {
todos(first: $first, skip: $skip) {
id
}
}
`, { first: 10 }); |
Beta Was this translation helpful? Give feedback.
-
@ispyinternet You can also use this oneliner: const user = query(operationStore(USER_QUERY)); |
Beta Was this translation helpful? Give feedback.
-
Awesome work on the new api (and fast too). I'm starting to change over my app to use it. I've got a couple of problems that I'm not sure how to solve. One is pausing the query, which is supported in the React examples for this reason.
I'm not currently looking to do anything like this, but I figure it could come up at some point. and the other is checking auth when routing between pages. I have an async function to check auth which awaits on a promise to return before redirecting. Not sure how to do that with the operationStore and Query. Any suggestions? |
Beta Was this translation helpful? Give feedback.
-
Upgrading from 0.4.0 to 1 it looks like typing has changed. It feels weird to me that data, error, etc are typed with a | void. Often I pass a graphql codegen type around and rather than having data? I get data? | void so I'm potentially passing void around which seems non-sensical to me...? It's not typed like this in, for instance, the react lib. Am I missing something? |
Beta Was this translation helpful? Give feedback.
-
I'm newish to svelte and urql. I'm struggling with the svelte api for subscriptions. I have followed the documentation on configuring the client using @urql/svelte for subscriptions. I can see the web socket connection to the server and the only subscription I have added: {
"id": "f635e52b-0d56-4513-8067-563ab2f3903e",
"type": "subscribe",
"payload": {
"key": "1h05np4",
"query": "subscription {\n postAdded {\n author {\n avatar\n name\n username\n }\n channel {\n _id\n }\n content\n updated\n }\n}\n",
"variables": {
"channelId": "6048ae93d145dde8a7ed7463"
},
"context": {
"url": "http://localhost:3001/graphql",
"fetchOptions": {
"headers": {
"Authorization": "Bearer {token}"
}
},
"preferGetMethod": false,
"suspense": false,
"requestPolicy": "cache-first",
"meta": {
"cacheOutcome": "miss"
},
"authAttempt": false
}
}
} I have added 2 operationStore(s), one as a query and one as a subscription. The docs are a little confusing on this point. Should I add one for the query and one for the subscription? Without the query, I get nothing returned from the server. Additionally, with or without the query, the subscription handler never gets called. const postAdded = operationStore(
`subscription{
postAdded{
author {
avatar
name
username
}
channel {
_id
}
content
updated
}
}`,
{ channelId: params.id }
);
subscription(postAdded, (previous = [], data) => {
console.log(`subscription::previous`, previous);
console.log(`subscription::data`, data);
}); Is there a full example of how to do a subscription, displaying not only changed data but existing data? Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm a big fan of Svelte and Urql. Now that SvelteKit is the new big thing, I have to ask. How is the support of server-side rendering with urql? |
Beta Was this translation helpful? Give feedback.
-
We've just made the step of resolving #1007. This means that we've reimplemented our
@urql/svelte
bindings and have released them asv1.0.0
. This is a big step for us in providing stable bindings for Svelte.While previous releases have tried varying different approaches and API designs. This time around we've taken all these learnings, resolved the bugs we've had before, and built an API that steers you towards the idiomatic and correct usage of the API.
So, what's new and how does it work?
All results and inputs to an
urql
Operation are now abstracted by theoperationStore
. This is simply a reactive primitive that will hold all values for the query and for the query's result. This may look very similar to a derived API, but it instead allows us to instruct Svelte to run all execution logic separately.You may create an
operationStore
like so:This is the shortest way to instantiate an
operationStore
. You can reactively update this store. It's just a Svelte writeable!However, not all logic will always live in components, so you can also directly update it:
The actual query may be started separately using the
query
call, which must be synchronous and will automatically attach anunsubscribe
cleanup callback toonDestroy
in the Svelte component.The query may then update
todos.data
,todos.error
,todos.fetching
and all the other fields automatically.How do I get started?
We've written extensive new docs to signal how to use this new API:
Hope y'all Svelters enjoy this release! And please do let us know how you get on with this API! 🙏
Beta Was this translation helpful? Give feedback.
All reactions