-
urql version & exchanges: Steps to reproduce // inside react component:
const client = useClient();
const submit = async () => {
const result = await client
.query(
GetRelatedData,
{ variable },
{ requestPolicy: "network-only" }
)
.toPromise();
//...restof the submit
}
Expected behavior Actual behavior In my case I'm fetching upload urls for each uploadable file, and each call returns a new url for upload. Each url can only be used once, so every upload requires an unique result that the server generates. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
Hiya ✌️ That's expected behaviour. To a certain extent, even without a cache it's expected that queries behave consistently and predictably — in other words, are side-effect free. It's likely a better idea to model your generation of upload URLs as a mutation instead if you're semi-randomly (at least as it looks from the outside) returning differing values. As per the spec; https://spec.graphql.org/October2021/#sec-Mutation
In reverse, hence some assumptions are made in https://formidable.com/open-source/urql/docs/architecture/#how-operations-get-to-exchanges So, you have two options:
So, while I'd recommend the second approach, it's also possible to use the first. As per what "request policies" mean; They only really alter what the cache does, however, they don't stop the |
Beta Was this translation helpful? Give feedback.
-
@villesau I've created this RFC to make this a little more intuitive in the future: #2184 For now, if you're sending identical mutations concurrently, I recommend you create some kind of altering key for each mutation. As mentioned, this is safe because that's what we do for changing instances, like files, automatically already: https://github.com/FormidableLabs/urql/blob/0b1c3d792b4bd2ca8699f77e06d05aca026926eb/packages/core/src/utils/stringifyVariables.ts#L25-L27 |
Beta Was this translation helpful? Give feedback.
-
For anyone landing here, I used @kitten's suggestion to add a variable to my query which is specific to the hook. const [skipCache] = useState(() => Math.random().toString(36))
const [query] = useFormInputQuery({
variables: { id, skipCache }
}) I added a |
Beta Was this translation helpful? Give feedback.
-
if anyone stumbles upon an issue where they want the query to run every time a submit button on a form is smashed but the query does not re trigger due to the input fields/variables passed being the same, you just have to execute the query manually:
|
Beta Was this translation helpful? Give feedback.
Hiya ✌️
That's expected behaviour. To a certain extent, even without a cache it's expected that queries behave consistently and predictably — in other words, are side-effect free. It's likely a better idea to model your generation of upload URLs as a mutation instead if you're semi-randomly (at least as it looks from the outside) returning differing values.
Otherwise
urql
may always assume, at least via thededupExchange
that the same query is repeatable. Even theClient
itself groups queries in the interest of avoiding work and registering whether a query is currently "active" or not by its keyAs per the spec; https://spec.graphql.org/October2021/#sec-Mutation