Skip to content

Commit e9b8d67

Browse files
committed
feat: query princible amount
1 parent 6240495 commit e9b8d67

18 files changed

Lines changed: 17848 additions & 70 deletions

File tree

.graphqlrc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// .graphqlrc.ts or graphql.config.ts
2+
export default {
3+
schema: 'http://10.10.20.72:3000/',
4+
documents: 'src/**/*.{graphql,js,ts,jsx,tsx}'
5+
};

codegen.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { CodegenConfig } from '@graphql-codegen/cli';
2+
3+
// https://subql-staging.orai.io/
4+
export const endpoint_gql = `http://10.10.20.72:3000/`;
5+
const config: CodegenConfig = {
6+
schema: endpoint_gql,
7+
documents: ['src/**/*.tsx'],
8+
// ignoreNoDocuments: true, // for better experience with the watcher
9+
generates: {
10+
'./src/gql/': {
11+
preset: 'client',
12+
plugins: []
13+
}
14+
}
15+
};
16+
17+
export default config;

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@
5757
"react-use-websocket": "3.0.0",
5858
"redux-persist": "^6.0.0",
5959
"serialize-error": "8.0.0",
60-
"tronweb": "^5.1.0"
60+
"tronweb": "^5.1.0",
61+
"urql": "^4.1.0"
6162
},
6263
"devDependencies": {
6364
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
6465
"@ethersproject/providers": "^5.0.10",
66+
"@graphql-codegen/cli": "^5.0.2",
67+
"@graphql-codegen/client-preset": "^4.3.3",
6568
"@keplr-wallet/types": "^0.11.38",
6669
"@oraichain/babel-plugin-operator-overloading": "^1.0.4",
6770
"@oraichain/common-contracts-build": "1.0.35",
@@ -78,6 +81,7 @@
7881
"@types/react-router-dom": "^5.3.3",
7982
"crypto-browserify": "^3.12.0",
8083
"firebase-tools": "^11.30.0",
84+
"graphql": "^16.9.0",
8185
"https-browserify": "^1.0.0",
8286
"husky": "^8.0.3",
8387
"node-polyfill-webpack-plugin": "^3.0.0",
@@ -103,7 +107,8 @@
103107
"postinstall": "patch-package",
104108
"prepare": "husky install",
105109
"ts-css": "typed-scss-modules src --watch --implementation sass -n all -e default",
106-
"clear-module-cache": "rm -rf node_modules/.cache/vendor & rm -rf public/vendor*"
110+
"clear-module-cache": "rm -rf node_modules/.cache/vendor & rm -rf public/vendor*",
111+
"codegen": "graphql-codegen"
107112
},
108113
"eslintConfig": {
109114
"extends": "react-app"

src/gql/fragment-masking.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* eslint-disable */
2+
import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core';
3+
import { FragmentDefinitionNode } from 'graphql';
4+
import { Incremental } from './graphql';
5+
6+
7+
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = TDocumentType extends DocumentTypeDecoration<
8+
infer TType,
9+
any
10+
>
11+
? [TType] extends [{ ' $fragmentName'?: infer TKey }]
12+
? TKey extends string
13+
? { ' $fragmentRefs'?: { [key in TKey]: TType } }
14+
: never
15+
: never
16+
: never;
17+
18+
// return non-nullable if `fragmentType` is non-nullable
19+
export function useFragment<TType>(
20+
_documentNode: DocumentTypeDecoration<TType, any>,
21+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
22+
): TType;
23+
// return nullable if `fragmentType` is undefined
24+
export function useFragment<TType>(
25+
_documentNode: DocumentTypeDecoration<TType, any>,
26+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
27+
): TType | undefined;
28+
// return nullable if `fragmentType` is nullable
29+
export function useFragment<TType>(
30+
_documentNode: DocumentTypeDecoration<TType, any>,
31+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
32+
): TType | null;
33+
// return nullable if `fragmentType` is nullable or undefined
34+
export function useFragment<TType>(
35+
_documentNode: DocumentTypeDecoration<TType, any>,
36+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
37+
): TType | null | undefined;
38+
// return array of non-nullable if `fragmentType` is array of non-nullable
39+
export function useFragment<TType>(
40+
_documentNode: DocumentTypeDecoration<TType, any>,
41+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
42+
): Array<TType>;
43+
// return array of nullable if `fragmentType` is array of nullable
44+
export function useFragment<TType>(
45+
_documentNode: DocumentTypeDecoration<TType, any>,
46+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
47+
): Array<TType> | null | undefined;
48+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
49+
export function useFragment<TType>(
50+
_documentNode: DocumentTypeDecoration<TType, any>,
51+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
52+
): ReadonlyArray<TType>;
53+
// return readonly array of nullable if `fragmentType` is array of nullable
54+
export function useFragment<TType>(
55+
_documentNode: DocumentTypeDecoration<TType, any>,
56+
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
57+
): ReadonlyArray<TType> | null | undefined;
58+
export function useFragment<TType>(
59+
_documentNode: DocumentTypeDecoration<TType, any>,
60+
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | Array<FragmentType<DocumentTypeDecoration<TType, any>>> | ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
61+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
62+
return fragmentType as any;
63+
}
64+
65+
66+
export function makeFragmentData<
67+
F extends DocumentTypeDecoration<any, any>,
68+
FT extends ResultOf<F>
69+
>(data: FT, _fragment: F): FragmentType<F> {
70+
return data as FragmentType<F>;
71+
}
72+
export function isFragmentReady<TQuery, TFrag>(
73+
queryNode: DocumentTypeDecoration<TQuery, any>,
74+
fragmentNode: TypedDocumentNode<TFrag>,
75+
data: FragmentType<TypedDocumentNode<Incremental<TFrag>, any>> | null | undefined
76+
): data is FragmentType<typeof fragmentNode> {
77+
const deferredFields = (queryNode as { __meta__?: { deferredFields: Record<string, (keyof TFrag)[]> } }).__meta__
78+
?.deferredFields;
79+
80+
if (!deferredFields) return true;
81+
82+
const fragDef = fragmentNode.definitions[0] as FragmentDefinitionNode | undefined;
83+
const fragName = fragDef?.name?.value;
84+
85+
const fields = (fragName && deferredFields[fragName]) || [];
86+
return fields.length > 0 && fields.every(field => data && field in data);
87+
}

src/gql/gql.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-disable */
2+
import * as types from './graphql';
3+
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
4+
5+
const documents = [];
6+
/**
7+
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
8+
*
9+
*
10+
* @example
11+
* ```ts
12+
* const query = graphql(`query GetUser($id: ID!) { user(id: $id) { name } }`);
13+
* ```
14+
*
15+
* The query argument is unknown!
16+
* Please regenerate the types.
17+
*/
18+
export function graphql(source: string): unknown;
19+
20+
export function graphql(source: string) {
21+
return (documents as any)[source] ?? {};
22+
}
23+
24+
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;

0 commit comments

Comments
 (0)