@constructive-io/graphql-react 2.14.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +89 -0
- package/context.d.ts +3 -0
- package/context.js +21 -0
- package/esm/context.js +14 -0
- package/esm/index.js +7 -0
- package/esm/provider.js +15 -0
- package/esm/use-constructive-client.js +16 -0
- package/esm/use-graphql-client.js +20 -0
- package/esm/use-introspection.js +41 -0
- package/esm/use-schema-meta.js +221 -0
- package/esm/use-table-rows.js +167 -0
- package/index.d.ts +7 -0
- package/index.js +23 -0
- package/package.json +44 -0
- package/provider.d.ts +5 -0
- package/provider.js +22 -0
- package/use-constructive-client.d.ts +2 -0
- package/use-constructive-client.js +19 -0
- package/use-graphql-client.d.ts +2 -0
- package/use-graphql-client.js +24 -0
- package/use-introspection.d.ts +130 -0
- package/use-introspection.js +44 -0
- package/use-schema-meta.d.ts +116 -0
- package/use-schema-meta.js +224 -0
- package/use-table-rows.d.ts +4 -0
- package/use-table-rows.js +173 -0
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./use-graphql-client"), exports);
|
|
18
|
+
__exportStar(require("./use-constructive-client"), exports);
|
|
19
|
+
__exportStar(require("./use-introspection"), exports);
|
|
20
|
+
__exportStar(require("./use-schema-meta"), exports);
|
|
21
|
+
__exportStar(require("./use-table-rows"), exports);
|
|
22
|
+
__exportStar(require("./provider"), exports);
|
|
23
|
+
__exportStar(require("./context"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@constructive-io/graphql-react",
|
|
3
|
+
"version": "2.14.10",
|
|
4
|
+
"author": "Constructive <developers@constructive.io>",
|
|
5
|
+
"description": "Constructive GraphQL React",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"homepage": "https://github.com/constructive-io/constructive",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/constructive-io/constructive"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/constructive-io/constructive/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "makage clean",
|
|
24
|
+
"prepack": "npm run build",
|
|
25
|
+
"build": "makage build",
|
|
26
|
+
"test": "jest --passWithNoTests",
|
|
27
|
+
"test:watch": "jest --watch"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@constructive-io/graphql-query": "^2.4.3",
|
|
31
|
+
"graphql-request": "^7.1.2",
|
|
32
|
+
"introspectron": "^2.14.10",
|
|
33
|
+
"react": "^19.1.0",
|
|
34
|
+
"react-dom": "^19.1.0",
|
|
35
|
+
"react-query": "^3.39.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@testing-library/jest-dom": "5.11.10",
|
|
39
|
+
"@testing-library/react": "11.2.5",
|
|
40
|
+
"@types/react": "^19.1.3",
|
|
41
|
+
"makage": "^0.1.8"
|
|
42
|
+
},
|
|
43
|
+
"gitHead": "22cfe32e994e26a6490e04e28bab26d1e7e6345c"
|
|
44
|
+
}
|
package/provider.d.ts
ADDED
package/provider.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.LqlProvider = void 0;
|
|
7
|
+
// @ts-nocheck
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
const context_1 = require("./context");
|
|
10
|
+
const LqlProvider = ({ endpointUrl, children }) => {
|
|
11
|
+
const LqlContext = (0, context_1.getLqlContext)();
|
|
12
|
+
return (react_1.default.createElement(LqlContext.Consumer, null, (context = {}) => {
|
|
13
|
+
if (endpointUrl && context.endpointUrl !== endpointUrl) {
|
|
14
|
+
context = Object.assign({}, context, { endpointUrl });
|
|
15
|
+
}
|
|
16
|
+
if (!context.endpointUrl) {
|
|
17
|
+
throw new Error('LqlProvider was not passed endpointUrl: ' + JSON.stringify(context));
|
|
18
|
+
}
|
|
19
|
+
return (react_1.default.createElement(LqlContext.Provider, { value: context }, children));
|
|
20
|
+
}));
|
|
21
|
+
};
|
|
22
|
+
exports.LqlProvider = LqlProvider;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConstructiveQuery = useConstructiveQuery;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const graphql_query_1 = require("@constructive-io/graphql-query");
|
|
6
|
+
const use_introspection_1 = require("./use-introspection");
|
|
7
|
+
const use_schema_meta_1 = require("./use-schema-meta");
|
|
8
|
+
function useConstructiveQuery() {
|
|
9
|
+
const introspection = (0, use_introspection_1.useIntrospection)();
|
|
10
|
+
const meta = (0, use_schema_meta_1.useSchemaMeta)();
|
|
11
|
+
return (0, react_1.useMemo)(() => {
|
|
12
|
+
if (!meta.data || !introspection.data)
|
|
13
|
+
return null;
|
|
14
|
+
return new graphql_query_1.QueryBuilder({
|
|
15
|
+
meta: graphql_query_1.MetaObject.convertFromMetaSchema({ _meta: meta.data }),
|
|
16
|
+
introspection: introspection.data
|
|
17
|
+
});
|
|
18
|
+
}, [introspection.data, meta.data]);
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useGraphqlClient = void 0;
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const graphql_request_1 = require("graphql-request");
|
|
7
|
+
const context_1 = require("./context");
|
|
8
|
+
const useGraphqlClient = () => {
|
|
9
|
+
const [endpointUrl, setEndpointUrl] = (0, react_1.useState)(null);
|
|
10
|
+
const [headers, setHeaders] = (0, react_1.useState)({});
|
|
11
|
+
const context = (0, react_1.useContext)((0, context_1.getLqlContext)());
|
|
12
|
+
if (!context || !context.endpointUrl) {
|
|
13
|
+
throw new Error('Missing LqlProvider');
|
|
14
|
+
}
|
|
15
|
+
if (endpointUrl != context.endpointUrl) {
|
|
16
|
+
setEndpointUrl(context.endpointUrl);
|
|
17
|
+
}
|
|
18
|
+
if (JSON.stringify(headers) != JSON.stringify(context.headers)) {
|
|
19
|
+
setHeaders(context.headers);
|
|
20
|
+
}
|
|
21
|
+
const graphqlClient = (0, react_1.useMemo)(() => (endpointUrl ? new graphql_request_1.GraphQLClient(endpointUrl, { headers }) : null), [headers, endpointUrl]);
|
|
22
|
+
return graphqlClient;
|
|
23
|
+
};
|
|
24
|
+
exports.useGraphqlClient = useGraphqlClient;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export declare function useIntrospection(options?: {}): {
|
|
2
|
+
data: undefined;
|
|
3
|
+
error: null;
|
|
4
|
+
isError: false;
|
|
5
|
+
isIdle: true;
|
|
6
|
+
isLoading: false;
|
|
7
|
+
isLoadingError: false;
|
|
8
|
+
isRefetchError: false;
|
|
9
|
+
isSuccess: false;
|
|
10
|
+
status: "idle";
|
|
11
|
+
dataUpdatedAt: number;
|
|
12
|
+
errorUpdatedAt: number;
|
|
13
|
+
failureCount: number;
|
|
14
|
+
errorUpdateCount: number;
|
|
15
|
+
isFetched: boolean;
|
|
16
|
+
isFetchedAfterMount: boolean;
|
|
17
|
+
isFetching: boolean;
|
|
18
|
+
isPlaceholderData: boolean;
|
|
19
|
+
isPreviousData: boolean;
|
|
20
|
+
isRefetching: boolean;
|
|
21
|
+
isStale: boolean;
|
|
22
|
+
remove: () => void;
|
|
23
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<{
|
|
24
|
+
[x: string]: any;
|
|
25
|
+
}, unknown>>;
|
|
26
|
+
} | {
|
|
27
|
+
data: undefined;
|
|
28
|
+
error: unknown;
|
|
29
|
+
isError: true;
|
|
30
|
+
isIdle: false;
|
|
31
|
+
isLoading: false;
|
|
32
|
+
isLoadingError: true;
|
|
33
|
+
isRefetchError: false;
|
|
34
|
+
isSuccess: false;
|
|
35
|
+
status: "error";
|
|
36
|
+
dataUpdatedAt: number;
|
|
37
|
+
errorUpdatedAt: number;
|
|
38
|
+
failureCount: number;
|
|
39
|
+
errorUpdateCount: number;
|
|
40
|
+
isFetched: boolean;
|
|
41
|
+
isFetchedAfterMount: boolean;
|
|
42
|
+
isFetching: boolean;
|
|
43
|
+
isPlaceholderData: boolean;
|
|
44
|
+
isPreviousData: boolean;
|
|
45
|
+
isRefetching: boolean;
|
|
46
|
+
isStale: boolean;
|
|
47
|
+
remove: () => void;
|
|
48
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<{
|
|
49
|
+
[x: string]: any;
|
|
50
|
+
}, unknown>>;
|
|
51
|
+
} | {
|
|
52
|
+
data: undefined;
|
|
53
|
+
error: null;
|
|
54
|
+
isError: false;
|
|
55
|
+
isIdle: false;
|
|
56
|
+
isLoading: true;
|
|
57
|
+
isLoadingError: false;
|
|
58
|
+
isRefetchError: false;
|
|
59
|
+
isSuccess: false;
|
|
60
|
+
status: "loading";
|
|
61
|
+
dataUpdatedAt: number;
|
|
62
|
+
errorUpdatedAt: number;
|
|
63
|
+
failureCount: number;
|
|
64
|
+
errorUpdateCount: number;
|
|
65
|
+
isFetched: boolean;
|
|
66
|
+
isFetchedAfterMount: boolean;
|
|
67
|
+
isFetching: boolean;
|
|
68
|
+
isPlaceholderData: boolean;
|
|
69
|
+
isPreviousData: boolean;
|
|
70
|
+
isRefetching: boolean;
|
|
71
|
+
isStale: boolean;
|
|
72
|
+
remove: () => void;
|
|
73
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<{
|
|
74
|
+
[x: string]: any;
|
|
75
|
+
}, unknown>>;
|
|
76
|
+
} | {
|
|
77
|
+
data: {
|
|
78
|
+
[x: string]: any;
|
|
79
|
+
};
|
|
80
|
+
error: unknown;
|
|
81
|
+
isError: true;
|
|
82
|
+
isIdle: false;
|
|
83
|
+
isLoading: false;
|
|
84
|
+
isLoadingError: false;
|
|
85
|
+
isRefetchError: true;
|
|
86
|
+
isSuccess: false;
|
|
87
|
+
status: "error";
|
|
88
|
+
dataUpdatedAt: number;
|
|
89
|
+
errorUpdatedAt: number;
|
|
90
|
+
failureCount: number;
|
|
91
|
+
errorUpdateCount: number;
|
|
92
|
+
isFetched: boolean;
|
|
93
|
+
isFetchedAfterMount: boolean;
|
|
94
|
+
isFetching: boolean;
|
|
95
|
+
isPlaceholderData: boolean;
|
|
96
|
+
isPreviousData: boolean;
|
|
97
|
+
isRefetching: boolean;
|
|
98
|
+
isStale: boolean;
|
|
99
|
+
remove: () => void;
|
|
100
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<{
|
|
101
|
+
[x: string]: any;
|
|
102
|
+
}, unknown>>;
|
|
103
|
+
} | {
|
|
104
|
+
data: {
|
|
105
|
+
[x: string]: any;
|
|
106
|
+
};
|
|
107
|
+
error: null;
|
|
108
|
+
isError: false;
|
|
109
|
+
isIdle: false;
|
|
110
|
+
isLoading: false;
|
|
111
|
+
isLoadingError: false;
|
|
112
|
+
isRefetchError: false;
|
|
113
|
+
isSuccess: true;
|
|
114
|
+
status: "success";
|
|
115
|
+
dataUpdatedAt: number;
|
|
116
|
+
errorUpdatedAt: number;
|
|
117
|
+
failureCount: number;
|
|
118
|
+
errorUpdateCount: number;
|
|
119
|
+
isFetched: boolean;
|
|
120
|
+
isFetchedAfterMount: boolean;
|
|
121
|
+
isFetching: boolean;
|
|
122
|
+
isPlaceholderData: boolean;
|
|
123
|
+
isPreviousData: boolean;
|
|
124
|
+
isRefetching: boolean;
|
|
125
|
+
isStale: boolean;
|
|
126
|
+
remove: () => void;
|
|
127
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<{
|
|
128
|
+
[x: string]: any;
|
|
129
|
+
}, unknown>>;
|
|
130
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIntrospection = useIntrospection;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_query_1 = require("react-query");
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
const introspectron_1 = require("introspectron");
|
|
8
|
+
const use_graphql_client_1 = require("./use-graphql-client");
|
|
9
|
+
const noop = () => { };
|
|
10
|
+
function useIntrospection(options = {}) {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const { headers, onSuccess = noop, onError = noop, ...restOptions } = options;
|
|
13
|
+
const graphqlClient = (0, use_graphql_client_1.useGraphqlClient)();
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
if (headers && graphqlClient) {
|
|
16
|
+
graphqlClient.setHeaders(headers);
|
|
17
|
+
}
|
|
18
|
+
}, [graphqlClient, headers]);
|
|
19
|
+
const { refetch, ...rest } = (0, react_query_1.useQuery)('introspection', async () => {
|
|
20
|
+
const introspectionResults = await graphqlClient.request(introspectron_1.IntrospectionQuery);
|
|
21
|
+
try {
|
|
22
|
+
const { queries, mutations } = (0, introspectron_1.parseGraphQuery)(introspectionResults);
|
|
23
|
+
return { ...queries, ...mutations };
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
throw new Error('useIntrospection: failed to get introspection query');
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
onError,
|
|
30
|
+
onSuccess,
|
|
31
|
+
...restOptions,
|
|
32
|
+
// The query will not execute until the graphqlClient exists
|
|
33
|
+
enabled: !!graphqlClient,
|
|
34
|
+
// SQL schema rarely changes, so we don't want it to invalidate too often
|
|
35
|
+
refetchInterval: false,
|
|
36
|
+
refetchIntervalInBackground: false,
|
|
37
|
+
refetchOnMount: false,
|
|
38
|
+
refetchOnWindowFocus: false
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
refetch,
|
|
42
|
+
...rest
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
export declare function useSchemaMeta({ tableName, onSuccess, onError, headers, ...restOptions }?: {}): {
|
|
2
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<any, unknown>>;
|
|
3
|
+
data: any;
|
|
4
|
+
error: null;
|
|
5
|
+
isError: false;
|
|
6
|
+
isIdle: true;
|
|
7
|
+
isLoading: false;
|
|
8
|
+
isLoadingError: false;
|
|
9
|
+
isRefetchError: false;
|
|
10
|
+
isSuccess: false;
|
|
11
|
+
status: "idle";
|
|
12
|
+
dataUpdatedAt: number;
|
|
13
|
+
errorUpdatedAt: number;
|
|
14
|
+
failureCount: number;
|
|
15
|
+
errorUpdateCount: number;
|
|
16
|
+
isFetched: boolean;
|
|
17
|
+
isFetchedAfterMount: boolean;
|
|
18
|
+
isFetching: boolean;
|
|
19
|
+
isPlaceholderData: boolean;
|
|
20
|
+
isPreviousData: boolean;
|
|
21
|
+
isRefetching: boolean;
|
|
22
|
+
isStale: boolean;
|
|
23
|
+
remove: () => void;
|
|
24
|
+
} | {
|
|
25
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<any, unknown>>;
|
|
26
|
+
data: any;
|
|
27
|
+
error: unknown;
|
|
28
|
+
isError: true;
|
|
29
|
+
isIdle: false;
|
|
30
|
+
isLoading: false;
|
|
31
|
+
isLoadingError: true;
|
|
32
|
+
isRefetchError: false;
|
|
33
|
+
isSuccess: false;
|
|
34
|
+
status: "error";
|
|
35
|
+
dataUpdatedAt: number;
|
|
36
|
+
errorUpdatedAt: number;
|
|
37
|
+
failureCount: number;
|
|
38
|
+
errorUpdateCount: number;
|
|
39
|
+
isFetched: boolean;
|
|
40
|
+
isFetchedAfterMount: boolean;
|
|
41
|
+
isFetching: boolean;
|
|
42
|
+
isPlaceholderData: boolean;
|
|
43
|
+
isPreviousData: boolean;
|
|
44
|
+
isRefetching: boolean;
|
|
45
|
+
isStale: boolean;
|
|
46
|
+
remove: () => void;
|
|
47
|
+
} | {
|
|
48
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<any, unknown>>;
|
|
49
|
+
data: any;
|
|
50
|
+
error: null;
|
|
51
|
+
isError: false;
|
|
52
|
+
isIdle: false;
|
|
53
|
+
isLoading: true;
|
|
54
|
+
isLoadingError: false;
|
|
55
|
+
isRefetchError: false;
|
|
56
|
+
isSuccess: false;
|
|
57
|
+
status: "loading";
|
|
58
|
+
dataUpdatedAt: number;
|
|
59
|
+
errorUpdatedAt: number;
|
|
60
|
+
failureCount: number;
|
|
61
|
+
errorUpdateCount: number;
|
|
62
|
+
isFetched: boolean;
|
|
63
|
+
isFetchedAfterMount: boolean;
|
|
64
|
+
isFetching: boolean;
|
|
65
|
+
isPlaceholderData: boolean;
|
|
66
|
+
isPreviousData: boolean;
|
|
67
|
+
isRefetching: boolean;
|
|
68
|
+
isStale: boolean;
|
|
69
|
+
remove: () => void;
|
|
70
|
+
} | {
|
|
71
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<any, unknown>>;
|
|
72
|
+
data: any;
|
|
73
|
+
error: unknown;
|
|
74
|
+
isError: true;
|
|
75
|
+
isIdle: false;
|
|
76
|
+
isLoading: false;
|
|
77
|
+
isLoadingError: false;
|
|
78
|
+
isRefetchError: true;
|
|
79
|
+
isSuccess: false;
|
|
80
|
+
status: "error";
|
|
81
|
+
dataUpdatedAt: number;
|
|
82
|
+
errorUpdatedAt: number;
|
|
83
|
+
failureCount: number;
|
|
84
|
+
errorUpdateCount: number;
|
|
85
|
+
isFetched: boolean;
|
|
86
|
+
isFetchedAfterMount: boolean;
|
|
87
|
+
isFetching: boolean;
|
|
88
|
+
isPlaceholderData: boolean;
|
|
89
|
+
isPreviousData: boolean;
|
|
90
|
+
isRefetching: boolean;
|
|
91
|
+
isStale: boolean;
|
|
92
|
+
remove: () => void;
|
|
93
|
+
} | {
|
|
94
|
+
refetch: <TPageData>(options?: import("react-query").RefetchOptions & import("react-query").RefetchQueryFilters<TPageData>) => Promise<import("react-query").QueryObserverResult<any, unknown>>;
|
|
95
|
+
data: any;
|
|
96
|
+
error: null;
|
|
97
|
+
isError: false;
|
|
98
|
+
isIdle: false;
|
|
99
|
+
isLoading: false;
|
|
100
|
+
isLoadingError: false;
|
|
101
|
+
isRefetchError: false;
|
|
102
|
+
isSuccess: true;
|
|
103
|
+
status: "success";
|
|
104
|
+
dataUpdatedAt: number;
|
|
105
|
+
errorUpdatedAt: number;
|
|
106
|
+
failureCount: number;
|
|
107
|
+
errorUpdateCount: number;
|
|
108
|
+
isFetched: boolean;
|
|
109
|
+
isFetchedAfterMount: boolean;
|
|
110
|
+
isFetching: boolean;
|
|
111
|
+
isPlaceholderData: boolean;
|
|
112
|
+
isPreviousData: boolean;
|
|
113
|
+
isRefetching: boolean;
|
|
114
|
+
isStale: boolean;
|
|
115
|
+
remove: () => void;
|
|
116
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSchemaMeta = useSchemaMeta;
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const graphql_request_1 = require("graphql-request");
|
|
7
|
+
const react_query_1 = require("react-query");
|
|
8
|
+
const use_graphql_client_1 = require("./use-graphql-client");
|
|
9
|
+
const fieldFragment = `
|
|
10
|
+
name
|
|
11
|
+
type {
|
|
12
|
+
gqlType
|
|
13
|
+
isArray
|
|
14
|
+
modifier
|
|
15
|
+
pgAlias
|
|
16
|
+
pgType
|
|
17
|
+
subtype
|
|
18
|
+
typmod
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const queryFragment = `
|
|
22
|
+
query {
|
|
23
|
+
all
|
|
24
|
+
create
|
|
25
|
+
delete
|
|
26
|
+
one
|
|
27
|
+
update
|
|
28
|
+
}
|
|
29
|
+
`;
|
|
30
|
+
const primaryConstraintsFragment = `
|
|
31
|
+
primaryKeyConstraints {
|
|
32
|
+
name
|
|
33
|
+
fields {
|
|
34
|
+
${fieldFragment}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const foreignKeyConstraintsFragments = `
|
|
39
|
+
foreignKeyConstraints {
|
|
40
|
+
name
|
|
41
|
+
fields {
|
|
42
|
+
${fieldFragment}
|
|
43
|
+
}
|
|
44
|
+
refFields {
|
|
45
|
+
${fieldFragment}
|
|
46
|
+
}
|
|
47
|
+
refTable {
|
|
48
|
+
name
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const inflectionFragment = `
|
|
53
|
+
inflection {
|
|
54
|
+
allRows
|
|
55
|
+
allRowsSimple
|
|
56
|
+
conditionType
|
|
57
|
+
connection
|
|
58
|
+
createField
|
|
59
|
+
createInputType
|
|
60
|
+
createPayloadType
|
|
61
|
+
deleteByPrimaryKey
|
|
62
|
+
deletePayloadType
|
|
63
|
+
edge
|
|
64
|
+
edgeField
|
|
65
|
+
enumType
|
|
66
|
+
filterType
|
|
67
|
+
inputType
|
|
68
|
+
orderByType
|
|
69
|
+
patchField
|
|
70
|
+
patchType
|
|
71
|
+
tableFieldName
|
|
72
|
+
tableType
|
|
73
|
+
typeName
|
|
74
|
+
updateByPrimaryKey
|
|
75
|
+
updatePayloadType
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
const metaQuery = (0, graphql_request_1.gql) `
|
|
79
|
+
query SchemaMetaQuery {
|
|
80
|
+
_meta {
|
|
81
|
+
tables {
|
|
82
|
+
name
|
|
83
|
+
${queryFragment}
|
|
84
|
+
|
|
85
|
+
${inflectionFragment}
|
|
86
|
+
|
|
87
|
+
fields {
|
|
88
|
+
${fieldFragment}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
${primaryConstraintsFragment}
|
|
92
|
+
|
|
93
|
+
${foreignKeyConstraintsFragments}
|
|
94
|
+
|
|
95
|
+
uniqueConstraints {
|
|
96
|
+
name
|
|
97
|
+
fields {
|
|
98
|
+
${fieldFragment}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
relations {
|
|
103
|
+
belongsTo {
|
|
104
|
+
fieldName
|
|
105
|
+
isUnique
|
|
106
|
+
type
|
|
107
|
+
keys {
|
|
108
|
+
${fieldFragment}
|
|
109
|
+
}
|
|
110
|
+
references {
|
|
111
|
+
name
|
|
112
|
+
fields {
|
|
113
|
+
${fieldFragment}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
has {
|
|
118
|
+
fieldName
|
|
119
|
+
isUnique
|
|
120
|
+
type
|
|
121
|
+
keys {
|
|
122
|
+
${fieldFragment}
|
|
123
|
+
}
|
|
124
|
+
referencedBy {
|
|
125
|
+
name
|
|
126
|
+
fields {
|
|
127
|
+
${fieldFragment}
|
|
128
|
+
}
|
|
129
|
+
${primaryConstraintsFragment}
|
|
130
|
+
${foreignKeyConstraintsFragments}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
hasMany {
|
|
134
|
+
fieldName
|
|
135
|
+
isUnique
|
|
136
|
+
type
|
|
137
|
+
keys {
|
|
138
|
+
${fieldFragment}
|
|
139
|
+
}
|
|
140
|
+
referencedBy {
|
|
141
|
+
name
|
|
142
|
+
fields {
|
|
143
|
+
${fieldFragment}
|
|
144
|
+
}
|
|
145
|
+
${primaryConstraintsFragment}
|
|
146
|
+
${foreignKeyConstraintsFragments}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
hasOne {
|
|
150
|
+
fieldName
|
|
151
|
+
isUnique
|
|
152
|
+
type
|
|
153
|
+
keys {
|
|
154
|
+
${fieldFragment}
|
|
155
|
+
}
|
|
156
|
+
referencedBy {
|
|
157
|
+
name
|
|
158
|
+
fields {
|
|
159
|
+
${fieldFragment}
|
|
160
|
+
}
|
|
161
|
+
${primaryConstraintsFragment}
|
|
162
|
+
${foreignKeyConstraintsFragments}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
manyToMany {
|
|
166
|
+
fieldName
|
|
167
|
+
type
|
|
168
|
+
leftKeyAttributes {
|
|
169
|
+
${fieldFragment}
|
|
170
|
+
}
|
|
171
|
+
rightKeyAttributes {
|
|
172
|
+
${fieldFragment}
|
|
173
|
+
}
|
|
174
|
+
junctionTable {
|
|
175
|
+
name
|
|
176
|
+
fields {
|
|
177
|
+
${fieldFragment}
|
|
178
|
+
}
|
|
179
|
+
${queryFragment}
|
|
180
|
+
${primaryConstraintsFragment}
|
|
181
|
+
${foreignKeyConstraintsFragments}
|
|
182
|
+
}
|
|
183
|
+
rightTable {
|
|
184
|
+
name
|
|
185
|
+
fields {
|
|
186
|
+
${fieldFragment}
|
|
187
|
+
}
|
|
188
|
+
${queryFragment}
|
|
189
|
+
${primaryConstraintsFragment}
|
|
190
|
+
${foreignKeyConstraintsFragments}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
function useSchemaMeta({ tableName, onSuccess, onError, headers, ...restOptions } = {}) {
|
|
199
|
+
const graphqlClient = (0, use_graphql_client_1.useGraphqlClient)();
|
|
200
|
+
(0, react_1.useEffect)(() => {
|
|
201
|
+
if (headers && graphqlClient) {
|
|
202
|
+
graphqlClient.setHeaders(headers);
|
|
203
|
+
}
|
|
204
|
+
}, [graphqlClient, headers]);
|
|
205
|
+
const { data, refetch, ...otherProps } = (0, react_query_1.useQuery)('schemaMeta', async () => {
|
|
206
|
+
return await graphqlClient.request(metaQuery);
|
|
207
|
+
}, {
|
|
208
|
+
onError,
|
|
209
|
+
onSuccess,
|
|
210
|
+
...restOptions,
|
|
211
|
+
// The query will not execute until the graphqlClient exists
|
|
212
|
+
enabled: !!graphqlClient,
|
|
213
|
+
// SQL schema rarely changes, so we don't want it to invalidate too often
|
|
214
|
+
refetchInterval: false,
|
|
215
|
+
refetchIntervalInBackground: false,
|
|
216
|
+
refetchOnMount: false,
|
|
217
|
+
refetchOnWindowFocus: false
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
...otherProps,
|
|
221
|
+
refetch,
|
|
222
|
+
data: tableName ? data?._meta?.tables[tableName] : data?._meta
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function useTableRowsPaginated(options?: {}): import("react-query").UseQueryResult<any, unknown>;
|
|
2
|
+
export declare function useTableRowsInfinite(options?: {}): import("react-query").UseInfiniteQueryResult<any, unknown>;
|
|
3
|
+
export declare function useCreateTableRow(options?: {}): import("react-query").UseMutationResult<any, unknown, void, unknown>;
|
|
4
|
+
export declare function useDeleteTableRow(options?: {}): import("react-query").UseMutationResult<any, unknown, void, unknown>;
|