From f56bdbbe306aa1876c58b25d38f7084322361134 Mon Sep 17 00:00:00 2001 From: MbBrainz Date: Fri, 19 Apr 2024 14:42:53 +0200 Subject: [PATCH] template/sketch of how react-query@5.x should look --- __output__/sg721/Sg721.react-query.ts | 130 ++++++++++++++++++-------- 1 file changed, 89 insertions(+), 41 deletions(-) diff --git a/__output__/sg721/Sg721.react-query.ts b/__output__/sg721/Sg721.react-query.ts index d575ea1e..13f82709 100644 --- a/__output__/sg721/Sg721.react-query.ts +++ b/__output__/sg721/Sg721.react-query.ts @@ -4,9 +4,10 @@ * and run the @cosmwasm/ts-codegen generate command to regenerate this file. */ -import { UseQueryOptions, useQuery } from "@tanstack/react-query"; -import { Expiration, Timestamp, Uint64, AllNftInfoResponse, OwnerOfResponse, Approval, NftInfoResponseForEmpty, Empty, AllOperatorsResponse, AllTokensResponse, ApprovalResponse, ApprovalsResponse, Decimal, CollectionInfoResponse, RoyaltyInfoResponse, ContractInfoResponse, ExecuteMsgForEmpty, Binary, MintMsgForEmpty, InstantiateMsg, CollectionInfoForRoyaltyInfoResponse, MinterResponse, NftInfoResponse, NumTokensResponse, OperatorsResponse, QueryMsg, TokensResponse } from "./Sg721.types"; +import { useQuery,UseQueryOptions } from "@tanstack/react-query"; + import { Sg721QueryClient } from "./Sg721.client"; +import { AllNftInfoResponse, AllOperatorsResponse, AllTokensResponse, ApprovalResponse, ApprovalsResponse, CollectionInfoResponse, ContractInfoResponse, MinterResponse, NftInfoResponse, NumTokensResponse, OwnerOfResponse, TokensResponse } from "./Sg721.types"; export interface Sg721ReactQuery { client: Sg721QueryClient; options?: Omit, "'queryKey' | 'queryFn' | 'initialData'"> & { @@ -18,14 +19,21 @@ export function useSg721CollectionInfoQuery({ client, options }: Sg721CollectionInfoQuery) { - return useQuery(["sg721CollectionInfo", client.contractAddress], () => client.collectionInfo(), options); + return useQuery({ + queryKey: ["sg721CollectionInfo", client.contractAddress], + queryFn: () => client.collectionInfo(), + ...options}); } export interface Sg721MinterQuery extends Sg721ReactQuery {} export function useSg721MinterQuery({ client, options }: Sg721MinterQuery) { - return useQuery(["sg721Minter", client.contractAddress], () => client.minter(), options); + return useQuery({ + queryKey: ["sg721Minter", client.contractAddress], + queryFn: () => client.minter(), + ...options + }); } export interface Sg721AllTokensQuery extends Sg721ReactQuery { args: { @@ -38,10 +46,14 @@ export function useSg721AllTokensQuery({ args, options }: Sg721AllTokensQuery) { - return useQuery(["sg721AllTokens", client.contractAddress, JSON.stringify(args)], () => client.allTokens({ - limit: args.limit, - startAfter: args.startAfter - }), options); + return useQuery({ + queryKey: ["sg721AllTokens", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.allTokens({ + limit: args.limit, + startAfter: args.startAfter + }), + ...options + }); } export interface Sg721TokensQuery extends Sg721ReactQuery { args: { @@ -55,11 +67,15 @@ export function useSg721TokensQuery({ args, options }: Sg721TokensQuery) { - return useQuery(["sg721Tokens", client.contractAddress, JSON.stringify(args)], () => client.tokens({ - limit: args.limit, - owner: args.owner, - startAfter: args.startAfter - }), options); + return useQuery({ + queryKey: ["sg721Tokens", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.tokens({ + limit: args.limit, + owner: args.owner, + startAfter: args.startAfter + }), + ...options + }); } export interface Sg721AllNftInfoQuery extends Sg721ReactQuery { args: { @@ -72,10 +88,14 @@ export function useSg721AllNftInfoQuery({ args, options }: Sg721AllNftInfoQuery) { - return useQuery(["sg721AllNftInfo", client.contractAddress, JSON.stringify(args)], () => client.allNftInfo({ - includeExpired: args.includeExpired, - tokenId: args.tokenId - }), options); + return useQuery({ + queryKey: ["sg721AllNftInfo", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.allNftInfo({ + includeExpired: args.includeExpired, + tokenId: args.tokenId + }), + ...options + }); } export interface Sg721NftInfoQuery extends Sg721ReactQuery { args: { @@ -87,23 +107,35 @@ export function useSg721NftInfoQuery({ args, options }: Sg721NftInfoQuery) { - return useQuery(["sg721NftInfo", client.contractAddress, JSON.stringify(args)], () => client.nftInfo({ - tokenId: args.tokenId - }), options); + return useQuery({ + queryKey: ["sg721NftInfo", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.nftInfo({ + tokenId: args.tokenId + }), + ...options + }); } export interface Sg721ContractInfoQuery extends Sg721ReactQuery {} export function useSg721ContractInfoQuery({ client, options }: Sg721ContractInfoQuery) { - return useQuery(["sg721ContractInfo", client.contractAddress], () => client.contractInfo(), options); + return useQuery({ + queryKey: ["sg721ContractInfo", client.contractAddress], + queryFn: () => client.contractInfo(), + ...options + }); } export interface Sg721NumTokensQuery extends Sg721ReactQuery {} export function useSg721NumTokensQuery({ client, options }: Sg721NumTokensQuery) { - return useQuery(["sg721NumTokens", client.contractAddress], () => client.numTokens(), options); + return useQuery({ + queryKey: ["sg721NumTokens", client.contractAddress], + queryFn: () => client.numTokens(), + ...options + }); } export interface Sg721AllOperatorsQuery extends Sg721ReactQuery { args: { @@ -118,12 +150,16 @@ export function useSg721AllOperatorsQuery({ args, options }: Sg721AllOperatorsQuery) { - return useQuery(["sg721AllOperators", client.contractAddress, JSON.stringify(args)], () => client.allOperators({ - includeExpired: args.includeExpired, - limit: args.limit, - owner: args.owner, - startAfter: args.startAfter - }), options); + return useQuery({ + queryKey: ["sg721AllOperators", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.allOperators({ + includeExpired: args.includeExpired, + limit: args.limit, + owner: args.owner, + startAfter: args.startAfter + }), + ...options + }); } export interface Sg721ApprovalsQuery extends Sg721ReactQuery { args: { @@ -136,10 +172,14 @@ export function useSg721ApprovalsQuery({ args, options }: Sg721ApprovalsQuery) { - return useQuery(["sg721Approvals", client.contractAddress, JSON.stringify(args)], () => client.approvals({ - includeExpired: args.includeExpired, - tokenId: args.tokenId - }), options); + return useQuery({ + queryKey: ["sg721Approvals", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.approvals({ + includeExpired: args.includeExpired, + tokenId: args.tokenId + }), + ...options + }); } export interface Sg721ApprovalQuery extends Sg721ReactQuery { args: { @@ -153,11 +193,15 @@ export function useSg721ApprovalQuery({ args, options }: Sg721ApprovalQuery) { - return useQuery(["sg721Approval", client.contractAddress, JSON.stringify(args)], () => client.approval({ - includeExpired: args.includeExpired, - spender: args.spender, - tokenId: args.tokenId - }), options); + return useQuery({ + queryKey: ["sg721Approval", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.approval({ + includeExpired: args.includeExpired, + spender: args.spender, + tokenId: args.tokenId + }), + ...options + }); } export interface Sg721OwnerOfQuery extends Sg721ReactQuery { args: { @@ -170,8 +214,12 @@ export function useSg721OwnerOfQuery({ args, options }: Sg721OwnerOfQuery) { - return useQuery(["sg721OwnerOf", client.contractAddress, JSON.stringify(args)], () => client.ownerOf({ - includeExpired: args.includeExpired, - tokenId: args.tokenId - }), options); + return useQuery({ + queryKey: ["sg721OwnerOf", client.contractAddress, JSON.stringify(args)], + queryFn: () => client.ownerOf({ + includeExpired: args.includeExpired, + tokenId: args.tokenId + }), + ...options + }); } \ No newline at end of file