Skip to content

Commit

Permalink
feat: use react-query and graphql-request
Browse files Browse the repository at this point in the history
  • Loading branch information
wgwz committed Jul 20, 2023
1 parent b0fda3b commit ec9df89
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ import { Wallet } from 'store/wallet.store'
import { EnableKeplr } from 'pages/enable-keplr-page'
import { InstallKeplr } from 'pages/install-keplr-page'
import { Loading } from '@/molecules/loading'
import request from 'graphql-request'
import { useQuery } from '@tanstack/react-query'
import { AllProposalsDocument } from 'gql/graphql'

export default function App() {
useKeplr()
const snap = useSnapshot(Wallet)
const { data } = useQuery(['proposals'], async () =>
request('http://localhost:5000/indexer/graphql', AllProposalsDocument),
)
console.log(data?.allProposals?.nodes)

switch (snap.keplrStatus) {
case 'ready':
Expand Down
5 changes: 5 additions & 0 deletions src/gql/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
* Therefore it is highly recommended to use the babel or swc plugin for production.
*/
const documents = {
"query AllProposals {\n allProposals {\n nodes {\n ...ProposalItem\n }\n }\n}": types.AllProposalsDocument,
"fragment ProposalItem on Proposal {\n type\n blockHeight\n txIdx\n msgIdx\n chainNum\n timestamp\n txHash\n id: proposalId\n status\n groupPolicyAddress\n groupPolicyVersion\n metadata\n proposers\n submitTime\n groupVersion\n groupPolicyAddress\n finalTallyResult\n votingPeriodEnd\n executorResult\n messages\n}": types.ProposalItemFragmentDoc,
"query ProposalsByGroupPolicyAddress($groupPolicyAddress: String!) {\n allProposals(condition: {groupPolicyAddress: $groupPolicyAddress}) {\n nodes {\n ...ProposalItem\n }\n }\n}": types.ProposalsByGroupPolicyAddressDocument,
};
Expand All @@ -31,6 +32,10 @@ const documents = {
*/
export function graphql(source: string): unknown;

/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "query AllProposals {\n allProposals {\n nodes {\n ...ProposalItem\n }\n }\n}"): (typeof documents)["query AllProposals {\n allProposals {\n nodes {\n ...ProposalItem\n }\n }\n}"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,14 @@ export type UpdateTxPayloadTxEdgeArgs = {
orderBy?: InputMaybe<Array<TxesOrderBy>>;
};

export type AllProposalsQueryVariables = Exact<{ [key: string]: never; }>;


export type AllProposalsQuery = { __typename?: 'Query', allProposals?: { __typename?: 'ProposalsConnection', nodes: Array<(
{ __typename?: 'Proposal' }
& { ' $fragmentRefs'?: { 'ProposalItemFragment': ProposalItemFragment } }
) | null> } | null };

export type ProposalItemFragment = { __typename?: 'Proposal', type: string, blockHeight: any, txIdx: number, msgIdx: number, chainNum: number, timestamp?: any | null, txHash: string, status: string, groupPolicyAddress: string, groupPolicyVersion: any, metadata: string, proposers: Array<string | null>, submitTime?: any | null, groupVersion: any, finalTallyResult: any, votingPeriodEnd: any, executorResult: string, messages: any, id: any } & { ' $fragmentName'?: 'ProposalItemFragment' };

export type ProposalsByGroupPolicyAddressQueryVariables = Exact<{
Expand All @@ -2743,4 +2751,5 @@ export type ProposalsByGroupPolicyAddressQuery = { __typename?: 'Query', allProp
) | null> } | null };

export const ProposalItemFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ProposalItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Proposal"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"blockHeight"}},{"kind":"Field","name":{"kind":"Name","value":"txIdx"}},{"kind":"Field","name":{"kind":"Name","value":"msgIdx"}},{"kind":"Field","name":{"kind":"Name","value":"chainNum"}},{"kind":"Field","name":{"kind":"Name","value":"timestamp"}},{"kind":"Field","name":{"kind":"Name","value":"txHash"}},{"kind":"Field","alias":{"kind":"Name","value":"id"},"name":{"kind":"Name","value":"proposalId"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyVersion"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"proposers"}},{"kind":"Field","name":{"kind":"Name","value":"submitTime"}},{"kind":"Field","name":{"kind":"Name","value":"groupVersion"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"finalTallyResult"}},{"kind":"Field","name":{"kind":"Name","value":"votingPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"executorResult"}},{"kind":"Field","name":{"kind":"Name","value":"messages"}}]}}]} as unknown as DocumentNode<ProposalItemFragment, unknown>;
export const AllProposalsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"AllProposals"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allProposals"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ProposalItem"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ProposalItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Proposal"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"blockHeight"}},{"kind":"Field","name":{"kind":"Name","value":"txIdx"}},{"kind":"Field","name":{"kind":"Name","value":"msgIdx"}},{"kind":"Field","name":{"kind":"Name","value":"chainNum"}},{"kind":"Field","name":{"kind":"Name","value":"timestamp"}},{"kind":"Field","name":{"kind":"Name","value":"txHash"}},{"kind":"Field","alias":{"kind":"Name","value":"id"},"name":{"kind":"Name","value":"proposalId"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyVersion"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"proposers"}},{"kind":"Field","name":{"kind":"Name","value":"submitTime"}},{"kind":"Field","name":{"kind":"Name","value":"groupVersion"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"finalTallyResult"}},{"kind":"Field","name":{"kind":"Name","value":"votingPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"executorResult"}},{"kind":"Field","name":{"kind":"Name","value":"messages"}}]}}]} as unknown as DocumentNode<AllProposalsQuery, AllProposalsQueryVariables>;
export const ProposalsByGroupPolicyAddressDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"ProposalsByGroupPolicyAddress"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"groupPolicyAddress"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allProposals"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"condition"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"groupPolicyAddress"},"value":{"kind":"Variable","name":{"kind":"Name","value":"groupPolicyAddress"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"nodes"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ProposalItem"}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ProposalItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Proposal"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"blockHeight"}},{"kind":"Field","name":{"kind":"Name","value":"txIdx"}},{"kind":"Field","name":{"kind":"Name","value":"msgIdx"}},{"kind":"Field","name":{"kind":"Name","value":"chainNum"}},{"kind":"Field","name":{"kind":"Name","value":"timestamp"}},{"kind":"Field","name":{"kind":"Name","value":"txHash"}},{"kind":"Field","alias":{"kind":"Name","value":"id"},"name":{"kind":"Name","value":"proposalId"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyVersion"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"proposers"}},{"kind":"Field","name":{"kind":"Name","value":"submitTime"}},{"kind":"Field","name":{"kind":"Name","value":"groupVersion"}},{"kind":"Field","name":{"kind":"Name","value":"groupPolicyAddress"}},{"kind":"Field","name":{"kind":"Name","value":"finalTallyResult"}},{"kind":"Field","name":{"kind":"Name","value":"votingPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"executorResult"}},{"kind":"Field","name":{"kind":"Name","value":"messages"}}]}}]} as unknown as DocumentNode<ProposalsByGroupPolicyAddressQuery, ProposalsByGroupPolicyAddressQueryVariables>;
7 changes: 7 additions & 0 deletions src/graphql/indexer/allProposals.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
query AllProposals {
allProposals {
nodes {
...ProposalItem
}
}
}

0 comments on commit ec9df89

Please sign in to comment.