Closed dadamu closed 2 years ago
so the client is ok, it's a mismatch between the react-query interface and implementation?
@adairrr have you experienced this? I think it could be a relatively simple fix. We may need to duplicate the interface if we're reusing it, and make a snake case version.
also, could be a use-case for https://github.com/sindresorhus/type-fest and we may not even need to duplicate the interface if I understand it correctly.
@pyramation yes, client is ok. The error happens in react-query files.
@dadamu can you send me the json schemas from which you're generating the code?
@adairrr sure, here it is https://github.com/CosmWasm/cw-nfts/tree/main/contracts/cw721-base/schema
I was able to repro the issue - should be an easy fix. It's interesting to me that the msg
uses the actual type instead of expanding it like everywhere else.
The schema references the type that's used:
{
"description": "Mint a new NFT, can only be called by the contract minter",
"type": "object",
"required": [
"mint"
],
"properties": {
"mint": {
"$ref": "#/definitions/MintMsg_for_Nullable_Empty"
}
},
"additionalProperties": false
},
At the revoke mutation, it uses the pascal case as well:
export interface Test721RevokeMutation {
client: Test721Client;
msg: {
spender: string;
tokenId: string;
};
args?: {...};
}
Ah, but there's no ref here.
{
"description": "Remove previously granted Approval",
"type": "object",
"required": [
"revoke"
],
"properties": {
"revoke": {
"type": "object",
"required": [
"spender",
"token_id"
],
"properties": {
"spender": {
"type": "string"
},
"token_id": {
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
@dadamu try this
Successfully published:
- @cosmwasm/ts-codegen@0.23.0
@pyramation Thanks for the help! However, after this changes, non-cw721 schema codegen will be error:
var msgType = (0, _utils.createTypedObjectParams)(context, jsonschema).typeAnnotation;
^
TypeError: Cannot read properties of undefined (reading 'typeAnnotation')
at createReactQueryMutationArgsInterface (~/node_modules/wasm-ast-types/main/react-query/react-query.js:209:73)
at ~/node_modules/wasm-ast-types/main/react-query/react-query.js:250:13
at Array.reduce (<anonymous>)
...
The whole schemas I used are here, both cw721-schemas and schemas.
In addition, StdFee
and Coin
are not imported properly after the last changes, I guess it is because the context.addUtil
are removed here.
Oof @dadamu that was totally my fault, apologies. Opened a new PR with the fixed changes. https://github.com/CosmWasm/ts-codegen/pull/86
The generated react query from cw721-base has the error in
useCw721BaseMintMutation
function from theCw721BaseMintMutation
with wrong type msg property. Themsg
inCw721BaseMintMutation
is using generated msg whose properties are in snake-case, it mismatches the clientmint
function to use the object with camel-case naming:Here is an example:
The structure of msg are snake case naming:
The client mint required args are camel case naming: