Francismiko
Francismiko2y ago

Calling storage.generateUploadUrl from the client

When I use TSX, this storage.generateUploadUrl api tells me that the argument for the rest parameter "args" was not provided. But when I checked the source code, it didn't seem to require parameters? (and there is really no such problem in js) I want to know what I need to do, such as adding a signature to my mutation function?
No description
No description
7 Replies
Francismiko
FrancismikoOP2y ago
my mutation function:
No description
Francismiko
FrancismikoOP2y ago
But I can normally get this url on the front end🤣
No description
ballingt
ballingt2y ago
It looks like the type of generateUploadUrl isn't flowing through to the frontend: (args: any) => Promise<any> is the default type used for a mutation when the actual type is unknown. You're right, it might be better spelled (args?: any) => Promise<any> because the args object (note not a rest parameter) is optional. But it would be especially interesting to figure out why the more specific type is not propagating for you. To work around you could cast the mutation, but there's something going on here worth fixing. Any other type errors? Is the mutation written in a .js or .ts file?
Francismiko
FrancismikoOP2y ago
No additional questions for now, my mutation function is in the TS file, thank you😁
ian
ian2y ago
Out of curiosity, does the type inference work if you wrap the function in {handler: async ({storage})… }? I had an odd typescript inference failure myself
Francismiko
FrancismikoOP2y ago
The strange thing is that when I pass it as a prop to call this mutation in the child component, it shows an optional parameter like 'arg?.'. And calling directly in the parent component will require me to use a { storageId } parameter
ian
ian2y ago
Looking at your code again, I think you trying to call the function in the client code, rather than using the react hook like useMutation('someFile:generateUploadUrl') I just made a mutation like yours and the types worked once I passed it into useMutation so if there's still something funky going on, there's probably some other code causing it.

Did you find this page helpful?