ruru-components 2.0.0-beta.2 → 2.0.0-beta.3
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/CHANGELOG.md +24 -0
- package/dist/components/Copy.d.ts +2 -1
- package/dist/components/Copy.d.ts.map +1 -1
- package/dist/components/Copy.js +8 -11
- package/dist/components/Copy.js.map +1 -1
- package/dist/components/ErrorPopup.js +2 -6
- package/dist/components/ErrorPopup.js.map +1 -1
- package/dist/components/Explain.d.ts +5 -0
- package/dist/components/Explain.d.ts.map +1 -1
- package/dist/components/Explain.js +46 -46
- package/dist/components/Explain.js.map +1 -1
- package/dist/components/Footer.js +2 -6
- package/dist/components/Footer.js.map +1 -1
- package/dist/components/FormatSQL.js +13 -17
- package/dist/components/FormatSQL.js.map +1 -1
- package/dist/components/Mermaid.d.ts +2 -1
- package/dist/components/Mermaid.d.ts.map +1 -1
- package/dist/components/Mermaid.js +24 -17
- package/dist/components/Mermaid.js.map +1 -1
- package/dist/defaultQuery.js +1 -4
- package/dist/defaultQuery.js.map +1 -1
- package/dist/hooks/useExplain.d.ts +1 -1
- package/dist/hooks/useExplain.js +9 -13
- package/dist/hooks/useExplain.js.map +1 -1
- package/dist/hooks/useFetcher.d.ts +5 -4
- package/dist/hooks/useFetcher.d.ts.map +1 -1
- package/dist/hooks/useFetcher.js +18 -22
- package/dist/hooks/useFetcher.js.map +1 -1
- package/dist/hooks/useGraphQLChangeStream.js +6 -10
- package/dist/hooks/useGraphQLChangeStream.js.map +1 -1
- package/dist/hooks/usePrettify.js +6 -10
- package/dist/hooks/usePrettify.js.map +1 -1
- package/dist/hooks/useSchema.js +14 -18
- package/dist/hooks/useSchema.js.map +1 -1
- package/dist/hooks/useStorage.d.ts +0 -2
- package/dist/hooks/useStorage.d.ts.map +1 -1
- package/dist/hooks/useStorage.js +5 -11
- package/dist/hooks/useStorage.js.map +1 -1
- package/dist/index.js +1 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js +1 -2
- package/dist/plugins/explain.js +9 -12
- package/dist/plugins/explain.js.map +1 -1
- package/dist/ruru.d.ts +1 -1
- package/dist/ruru.d.ts.map +1 -1
- package/dist/ruru.js +41 -44
- package/dist/ruru.js.map +1 -1
- package/package.json +28 -21
package/dist/hooks/useFetcher.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const graphql_1 = require("graphql");
|
|
6
|
-
const graphql_ws_1 = require("graphql-ws");
|
|
7
|
-
const react_1 = require("react");
|
|
1
|
+
import { createGraphiQLFetcher, isAsyncIterable, isPromise, } from "@graphiql/toolkit";
|
|
2
|
+
import { getOperationAST, parse } from "graphql";
|
|
3
|
+
import { createClient } from "graphql-ws";
|
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
|
8
5
|
const isExplainOperationLike = (op) => {
|
|
9
6
|
return (typeof op === "object" &&
|
|
10
7
|
op &&
|
|
@@ -24,8 +21,8 @@ const isIntrospectionQuery = (params) => {
|
|
|
24
21
|
if (params.operationName) {
|
|
25
22
|
return false;
|
|
26
23
|
}
|
|
27
|
-
const ast =
|
|
28
|
-
const def =
|
|
24
|
+
const ast = parse(params.query);
|
|
25
|
+
const def = getOperationAST(ast, params.operationName);
|
|
29
26
|
if (def?.name?.value === "IntrospectionQuery") {
|
|
30
27
|
return true;
|
|
31
28
|
}
|
|
@@ -51,8 +48,8 @@ function hideProperty(obj, property) {
|
|
|
51
48
|
delete obj[property];
|
|
52
49
|
Object.defineProperty(obj, property, { value, enumerable: false });
|
|
53
50
|
}
|
|
54
|
-
const useFetcher = (props, options = {}) => {
|
|
55
|
-
const [streamEndpoint, setStreamEndpoint] =
|
|
51
|
+
export const useFetcher = (props, options = {}) => {
|
|
52
|
+
const [streamEndpoint, setStreamEndpoint] = useState(null);
|
|
56
53
|
const endpoint = props.endpoint ?? "/graphql";
|
|
57
54
|
const url = endpoint.startsWith("/")
|
|
58
55
|
? (typeof window !== "undefined" ? window.location.origin : "") + endpoint
|
|
@@ -62,9 +59,9 @@ const useFetcher = (props, options = {}) => {
|
|
|
62
59
|
: props.endpoint
|
|
63
60
|
? makeWsUrl(props.endpoint)
|
|
64
61
|
: undefined;
|
|
65
|
-
const [explainResults, setExplainResults] =
|
|
62
|
+
const [explainResults, setExplainResults] = useState(null);
|
|
66
63
|
// Reset the stream endpoint every time the URL changes.
|
|
67
|
-
|
|
64
|
+
useEffect(() => {
|
|
68
65
|
if (url) {
|
|
69
66
|
setStreamEndpoint(null);
|
|
70
67
|
}
|
|
@@ -72,7 +69,7 @@ const useFetcher = (props, options = {}) => {
|
|
|
72
69
|
const explain = options.explain &&
|
|
73
70
|
(!props.debugTools || props.debugTools.includes("explain"));
|
|
74
71
|
const verbose = !!options.verbose;
|
|
75
|
-
const ourFetch =
|
|
72
|
+
const ourFetch = useMemo(() => {
|
|
76
73
|
return (...args) => {
|
|
77
74
|
const result = fetch(...args);
|
|
78
75
|
result.then((response) => {
|
|
@@ -85,25 +82,25 @@ const useFetcher = (props, options = {}) => {
|
|
|
85
82
|
return result;
|
|
86
83
|
};
|
|
87
84
|
}, [url]);
|
|
88
|
-
const fetcherOptions =
|
|
85
|
+
const fetcherOptions = useMemo(() => ({
|
|
89
86
|
url,
|
|
90
87
|
headers: {
|
|
91
88
|
...(explain
|
|
92
89
|
? {
|
|
93
90
|
"X-PostGraphile-Explain": "on",
|
|
94
|
-
"X-GraphQL-Explain": "
|
|
91
|
+
"X-GraphQL-Explain": "plan,sql",
|
|
95
92
|
}
|
|
96
93
|
: null),
|
|
97
94
|
},
|
|
98
95
|
fetch: ourFetch,
|
|
99
96
|
wsClient: subscriptionUrl
|
|
100
|
-
?
|
|
97
|
+
? createClient({
|
|
101
98
|
url: subscriptionUrl,
|
|
102
99
|
})
|
|
103
100
|
: undefined,
|
|
104
101
|
}), [explain, url, subscriptionUrl, ourFetch]);
|
|
105
|
-
const fetcher =
|
|
106
|
-
const wrappedFetcher =
|
|
102
|
+
const fetcher = useMemo(() => props.fetcher ?? createGraphiQLFetcher(fetcherOptions), [fetcherOptions, props.fetcher]);
|
|
103
|
+
const wrappedFetcher = useMemo(() => {
|
|
107
104
|
const processPayload = (inResult) => {
|
|
108
105
|
if (inResult == null) {
|
|
109
106
|
return inResult;
|
|
@@ -167,7 +164,7 @@ const useFetcher = (props, options = {}) => {
|
|
|
167
164
|
// TODO: support wrapping subscriptions
|
|
168
165
|
return result;
|
|
169
166
|
}
|
|
170
|
-
else if (
|
|
167
|
+
else if (isAsyncIterable(result)) {
|
|
171
168
|
const iterator = result[Symbol.asyncIterator]();
|
|
172
169
|
// Return a new iterator, equivalent to the old, but that calls 'processPayload'
|
|
173
170
|
return {
|
|
@@ -175,7 +172,7 @@ const useFetcher = (props, options = {}) => {
|
|
|
175
172
|
return: iterator.return?.bind(iterator),
|
|
176
173
|
next(...args) {
|
|
177
174
|
const n = iterator.next(...args);
|
|
178
|
-
if (
|
|
175
|
+
if (isPromise(n)) {
|
|
179
176
|
return n.then(({ done, value }) => {
|
|
180
177
|
return { done, value: processPayload(value) };
|
|
181
178
|
});
|
|
@@ -197,5 +194,4 @@ const useFetcher = (props, options = {}) => {
|
|
|
197
194
|
}, [fetcher, verbose]);
|
|
198
195
|
return { fetcher: wrappedFetcher, explainResults, streamEndpoint };
|
|
199
196
|
};
|
|
200
|
-
exports.useFetcher = useFetcher;
|
|
201
197
|
//# sourceMappingURL=useFetcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetcher.js","sourceRoot":"","sources":["../../src/hooks/useFetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFetcher.js","sourceRoot":"","sources":["../../src/hooks/useFetcher.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,SAAS,GACV,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC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
|
-
|
|
4
|
-
const
|
|
5
|
-
const useGraphQLChangeStream = (props, refetch, streamEndpoint) => {
|
|
6
|
-
const [error, setError] = (0, react_1.useState)(null);
|
|
7
|
-
const eventSourceRef = (0, react_1.useRef)(null);
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
export const useGraphQLChangeStream = (props, refetch, streamEndpoint) => {
|
|
3
|
+
const [error, setError] = useState(null);
|
|
4
|
+
const eventSourceRef = useRef(null);
|
|
8
5
|
// Starts listening to the event stream at the `sourceUrl`.
|
|
9
|
-
|
|
6
|
+
useEffect(() => {
|
|
10
7
|
eventSourceRef.current = streamEndpoint
|
|
11
8
|
? new EventSource(streamEndpoint)
|
|
12
9
|
: null;
|
|
@@ -22,7 +19,7 @@ const useGraphQLChangeStream = (props, refetch, streamEndpoint) => {
|
|
|
22
19
|
};
|
|
23
20
|
}, [streamEndpoint]);
|
|
24
21
|
const eventSource = eventSourceRef.current;
|
|
25
|
-
|
|
22
|
+
useEffect(() => {
|
|
26
23
|
if (eventSource) {
|
|
27
24
|
if (eventSource.readyState === eventSource.CLOSED) {
|
|
28
25
|
throw new Error("Lifecycle management error for EventSource");
|
|
@@ -51,5 +48,4 @@ const useGraphQLChangeStream = (props, refetch, streamEndpoint) => {
|
|
|
51
48
|
}, [error, eventSource, refetch, streamEndpoint]);
|
|
52
49
|
return { error };
|
|
53
50
|
};
|
|
54
|
-
exports.useGraphQLChangeStream = useGraphQLChangeStream;
|
|
55
51
|
//# sourceMappingURL=useGraphQLChangeStream.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraphQLChangeStream.js","sourceRoot":"","sources":["../../src/hooks/useGraphQLChangeStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGraphQLChangeStream.js","sourceRoot":"","sources":["../../src/hooks/useGraphQLChangeStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAA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AE,KAAK,CAAC,CAAC;gBAChE,QAAQ,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAC;YAEF,mEAAmE;YACnE,WAAW,CAAC,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACvD,2DAA2D;YAC3D,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YACpD,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAEtD,2DAA2D;YAC3D,OAAO,GAAG,EAAE;gBACV,WAAW,CAAC,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC1D,WAAW,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBACvD,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAC3D,CAAC,CAAC;SACH;IACH,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;IAClD,OAAO,EAAE,KAAK,EAAE,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.usePrettify = void 0;
|
|
4
|
-
const react_1 = require("@graphiql/react");
|
|
5
|
-
const react_2 = require("react");
|
|
1
|
+
import { useEditorContext, usePrettifyEditors } from "@graphiql/react";
|
|
2
|
+
import { useCallback } from "react";
|
|
6
3
|
/**
|
|
7
4
|
* Prettifies with 'prettier' if available, otherwise using GraphiQL's built in
|
|
8
5
|
* prettify.
|
|
9
6
|
*/
|
|
10
|
-
const usePrettify = () => {
|
|
11
|
-
const editorContext =
|
|
12
|
-
const fallbackPrettify =
|
|
13
|
-
return
|
|
7
|
+
export const usePrettify = () => {
|
|
8
|
+
const editorContext = useEditorContext();
|
|
9
|
+
const fallbackPrettify = usePrettifyEditors();
|
|
10
|
+
return useCallback(() => {
|
|
14
11
|
const queryEditor = editorContext?.queryEditor;
|
|
15
12
|
if (!queryEditor) {
|
|
16
13
|
return;
|
|
@@ -29,5 +26,4 @@ const usePrettify = () => {
|
|
|
29
26
|
}
|
|
30
27
|
}, [editorContext?.queryEditor, fallbackPrettify]);
|
|
31
28
|
};
|
|
32
|
-
exports.usePrettify = usePrettify;
|
|
33
29
|
//# sourceMappingURL=usePrettify.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrettify.js","sourceRoot":"","sources":["../../src/hooks/usePrettify.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePrettify.js","sourceRoot":"","sources":["../../src/hooks/usePrettify.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AASpC;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,MAAM,aAAa,GAAG,gBAAgB,EAAE,CAAC;IACzC,MAAM,gBAAgB,GAAG,kBAAkB,EAAE,CAAC;IAC9C,OAAO,WAAW,CAAC,GAAG,EAAE;QACtB,MAAM,WAAW,GAAG,aAAa,EAAE,WAAW,CAAC;QAC/C,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO;SACR;QACD,IACE,WAAW;YACX,OAAO,MAAM,CAAC,QAAQ,KAAK,WAAW;YACtC,OAAO,MAAM,CAAC,eAAe,KAAK,WAAW,EAC7C;YACA,yCAAyC;YACzC,WAAW,CAAC,QAAQ,CAClB,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE;gBAC7C,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,MAAM,CAAC,eAAe;aAChC,CAAC,CACH,CAAC;SACH;aAAM;YACL,gBAAgB,EAAE,CAAC;SACpB;IACH,CAAC,EAAE,CAAC,aAAa,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC"}
|
package/dist/hooks/useSchema.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const toolkit_1 = require("@graphiql/toolkit");
|
|
5
|
-
const graphql_1 = require("graphql");
|
|
6
|
-
const react_1 = require("react");
|
|
1
|
+
import { isAsyncIterable } from "@graphiql/toolkit";
|
|
2
|
+
import { buildClientSchema, getIntrospectionQuery, GraphQLError, } from "graphql";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
4
|
// import { updateGraphiQLDocExplorerNavStack } from "../updateGraphiQLDocExplorerNavStack.js";
|
|
8
|
-
|
|
9
|
-
const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
10
|
-
const [schema, setSchema] =
|
|
11
|
-
const refetchStatusRef =
|
|
5
|
+
import { useGraphQLChangeStream } from "./useGraphQLChangeStream.js";
|
|
6
|
+
export const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
7
|
+
const [schema, setSchema] = useState(null);
|
|
8
|
+
const refetchStatusRef = useRef({
|
|
12
9
|
inProgress: false,
|
|
13
10
|
fetchAgain: null,
|
|
14
11
|
});
|
|
15
|
-
const refetch =
|
|
12
|
+
const refetch = useCallback(() => {
|
|
16
13
|
if (refetchStatusRef.current.inProgress) {
|
|
17
14
|
refetchStatusRef.current.fetchAgain = refetch;
|
|
18
15
|
return;
|
|
@@ -23,11 +20,11 @@ const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
|
23
20
|
// Fetch the schema using our introspection query and report once that has
|
|
24
21
|
// finished.
|
|
25
22
|
const result = await fetcher({
|
|
26
|
-
query:
|
|
23
|
+
query: getIntrospectionQuery(),
|
|
27
24
|
operationName: null,
|
|
28
25
|
});
|
|
29
26
|
let payload;
|
|
30
|
-
if (
|
|
27
|
+
if (isAsyncIterable(result)) {
|
|
31
28
|
// Handle async iterator; we're only expecting a single payload.
|
|
32
29
|
for await (const entry of result) {
|
|
33
30
|
payload = entry;
|
|
@@ -39,7 +36,7 @@ const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
|
39
36
|
const { data, errors } = payload;
|
|
40
37
|
if (errors) {
|
|
41
38
|
if (errors[0]) {
|
|
42
|
-
throw new
|
|
39
|
+
throw new GraphQLError(errors[0].message ?? "Error has no message?!", null, null, null, errors[0].path, null, errors[0].extensions);
|
|
43
40
|
}
|
|
44
41
|
else {
|
|
45
42
|
throw new Error("'errors' was set on the payload, but was empty or contained null? This is forbidden by the GraphQL spec.");
|
|
@@ -47,7 +44,7 @@ const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
|
47
44
|
}
|
|
48
45
|
// Use the data we got back from GraphQL to build a client schema (a
|
|
49
46
|
// schema without resolvers).
|
|
50
|
-
const schema =
|
|
47
|
+
const schema = buildClientSchema(data);
|
|
51
48
|
setSchema(schema);
|
|
52
49
|
setError(null);
|
|
53
50
|
console.log("Ruru: Schema updated");
|
|
@@ -64,11 +61,10 @@ const useSchema = (props, fetcher, setError, streamEndpoint) => {
|
|
|
64
61
|
}
|
|
65
62
|
});
|
|
66
63
|
}, [fetcher, setError]);
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
useGraphQLChangeStream(props, refetch, streamEndpoint);
|
|
65
|
+
useEffect(() => {
|
|
69
66
|
refetch();
|
|
70
67
|
}, [refetch]);
|
|
71
68
|
return { schema };
|
|
72
69
|
};
|
|
73
|
-
exports.useSchema = useSchema;
|
|
74
70
|
//# sourceMappingURL=useSchema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSchema.js","sourceRoot":"","sources":["../../src/hooks/useSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSchema.js","sourceRoot":"","sources":["../../src/hooks/useSchema.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;IACxB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,EAAE,CAAC;IACZ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,EAAE,MAAM,EAAE,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
export interface StoredKeys {
|
|
2
2
|
saveHeaders: "true" | "";
|
|
3
|
-
headers: string;
|
|
4
3
|
explain: "true" | "";
|
|
5
4
|
explorerIsOpen: "true" | "";
|
|
6
5
|
explainIsOpen: "true" | "";
|
|
7
6
|
explainAtBottom: "true" | "";
|
|
8
7
|
explainSize: string;
|
|
9
|
-
query: string;
|
|
10
8
|
verbose: "true" | "";
|
|
11
9
|
}
|
|
12
10
|
export interface RuruStorage {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useStorage.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,GAAG,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"useStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useStorage.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,GAAG,EAAE,CAAC;IACzB,OAAO,EAAE,MAAM,GAAG,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,GAAG,EAAE,CAAC;IAC5B,aAAa,EAAE,MAAM,GAAG,EAAE,CAAC;IAC3B,eAAe,EAAE,MAAM,GAAG,EAAE,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,EAAE,CAAC;CACtB;AAcD,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,IAAI,SAAS,MAAM,UAAU,EAAE,GAAG,EAAE,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACvE,GAAG,CAAC,IAAI,SAAS,MAAM,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7E,MAAM,CAAC,IAAI,SAAS,MAAM,UAAU,EAAE,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CACxD;AAED,eAAO,MAAM,UAAU,QAAO,WA4C7B,CAAC"}
|
package/dist/hooks/useStorage.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStorage = void 0;
|
|
4
|
-
const react_1 = require("react");
|
|
1
|
+
import { useMemo, useState } from "react";
|
|
5
2
|
const KEYS = {
|
|
6
3
|
saveHeaders: "Ruru:saveHeadersText",
|
|
7
|
-
headers: "Ruru:headersText",
|
|
8
4
|
explain: "Ruru:explain",
|
|
9
5
|
explainSize: "Ruru:explainSize",
|
|
10
6
|
explainIsOpen: "Ruru:explainIsOpen",
|
|
11
7
|
explainAtBottom: "Ruru:explainAtBottom",
|
|
12
8
|
explorerIsOpen: "graphiql:explorerIsOpen",
|
|
13
|
-
query: "graphiql:query",
|
|
14
9
|
verbose: "Ruru:verbose",
|
|
15
10
|
};
|
|
16
11
|
const up = (v) => v + 1;
|
|
17
|
-
const useStorage = () => {
|
|
12
|
+
export const useStorage = () => {
|
|
18
13
|
const storage = typeof window !== "undefined" ? window.localStorage : null;
|
|
19
14
|
// Trigger re-render every time we set
|
|
20
|
-
const [revision, bump] =
|
|
21
|
-
const [cache] =
|
|
22
|
-
return
|
|
15
|
+
const [revision, bump] = useState(0);
|
|
16
|
+
const [cache] = useState(Object.create(null));
|
|
17
|
+
return useMemo(() => {
|
|
23
18
|
if (!storage) {
|
|
24
19
|
return {
|
|
25
20
|
_revision: revision,
|
|
@@ -59,5 +54,4 @@ const useStorage = () => {
|
|
|
59
54
|
};
|
|
60
55
|
}, [storage, revision, cache]);
|
|
61
56
|
};
|
|
62
|
-
exports.useStorage = useStorage;
|
|
63
57
|
//# sourceMappingURL=useStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.js","sourceRoot":"","sources":["../../src/hooks/useStorage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useStorage.js","sourceRoot":"","sources":["../../src/hooks/useStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAY1C,MAAM,IAAI,GAA0C;IAClD,WAAW,EAAE,sBAAsB;IACnC,OAAO,EAAE,cAAc;IACvB,WAAW,EAAE,kBAAkB;IAC/B,aAAa,EAAE,oBAAoB;IACnC,eAAe,EAAE,sBAAsB;IACvC,cAAc,EAAE,yBAAyB;IACzC,OAAO,EAAE,cAAc;CACxB,CAAC;AAEF,MAAM,EAAE,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAQhC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAgB,EAAE;IAC1C,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,sCAAsC;IACtC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAsB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnE,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,OAAO,EAAE;YACZ,OAAO;gBACL,SAAS,EAAE,QAAQ;gBACnB,GAAG,CAAC,GAAG;oBACL,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;gBAC5B,CAAC;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Ruru = void 0;
|
|
4
|
-
var ruru_js_1 = require("./ruru.js");
|
|
5
|
-
Object.defineProperty(exports, "Ruru", { enumerable: true, get: function () { return ruru_js_1.Ruru; } });
|
|
1
|
+
export { Ruru } from "./ruru.js";
|
|
6
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/interfaces.js
CHANGED
package/dist/plugins/explain.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const react_2 = require("react");
|
|
7
|
-
const Explain_js_1 = require("../components/Explain.js");
|
|
8
|
-
const useExplain_js_1 = require("../hooks/useExplain.js");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MagnifyingGlassIcon } from "@graphiql/react";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { Explain } from "../components/Explain.js";
|
|
5
|
+
import { ExplainContext } from "../hooks/useExplain.js";
|
|
9
6
|
const ExplainPanel = () => {
|
|
10
|
-
const { explainHelpers, explain, explainResults, setExplain } =
|
|
11
|
-
return ((
|
|
7
|
+
const { explainHelpers, explain, explainResults, setExplain } = useContext(ExplainContext);
|
|
8
|
+
return (_jsxs("div", { children: [_jsx("div", { className: "graphiql-doc-explorer-header", children: _jsx("div", { className: "graphiql-doc-explorer-title", children: "Explain" }) }), _jsx("div", { className: "graphiql-doc-explorer-content", children: _jsx(Explain, { explain: explain, setExplain: setExplain, helpers: explainHelpers, results: explainResults }) })] }));
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export const EXPLAIN_PLUGIN = {
|
|
14
11
|
title: "Explain",
|
|
15
|
-
icon:
|
|
12
|
+
icon: MagnifyingGlassIcon,
|
|
16
13
|
content: ExplainPanel,
|
|
17
14
|
};
|
|
18
15
|
//# sourceMappingURL=explain.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/plugins/explain.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"explain.js","sourceRoot":"","sources":["../../src/plugins/explain.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,YAAY,GAAO,GAAG,EAAE;IAC5B,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,GAC3D,UAAU,CAAC,cAAc,CAAC,CAAC;IAE7B,OAAO,CACL,0BACE,cAAK,SAAS,EAAC,8BAA8B,YAC3C,cAAK,SAAS,EAAC,6BAA6B,wBAAc,GACtD,EACN,cAAK,SAAS,EAAC,+BAA+B,YAC5C,KAAC,OAAO,IACN,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,cAAc,GACvB,GACE,IACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,mBAAmB;IACzB,OAAO,EAAE,YAAY;CACtB,CAAC"}
|
package/dist/ruru.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export declare const RuruInner: FC<{
|
|
|
8
8
|
storage: RuruStorage;
|
|
9
9
|
error: Error | null;
|
|
10
10
|
setError: React.Dispatch<React.SetStateAction<Error | null>>;
|
|
11
|
-
onEditQuery
|
|
11
|
+
onEditQuery?: GraphiQLProps["onEditQuery"];
|
|
12
12
|
}>;
|
|
13
13
|
//# sourceMappingURL=ruru.d.ts.map
|
package/dist/ruru.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruru.d.ts","sourceRoot":"","sources":["../src/ruru.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ruru.d.ts","sourceRoot":"","sources":["../src/ruru.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAUhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAWjD,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,SAAS,CAmD9B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;IACrB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;IAC7D,WAAW,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;CAC5C,CAgHA,CAAC"}
|
package/dist/ruru.js
CHANGED
|
@@ -1,74 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { explorerPlugin as makeExplorerPlugin } from "@graphiql/plugin-explorer";
|
|
3
|
+
import { CopyIcon, GraphiQLProvider as GP2, MergeIcon, PrettifyIcon, SettingsIcon, ToolbarButton, ToolbarMenu, useCopyQuery, useMergeQuery, } from "@graphiql/react";
|
|
4
|
+
import { GraphiQL, GraphiQLInterface, GraphiQLProvider } from "graphiql";
|
|
5
|
+
import { useCallback, useMemo, useState } from "react";
|
|
6
|
+
import { ErrorPopup } from "./components/ErrorPopup.js";
|
|
7
|
+
import { RuruFooter } from "./components/Footer.js";
|
|
8
|
+
import { defaultQuery as DEFAULT_QUERY } from "./defaultQuery.js";
|
|
9
|
+
import { ExplainContext, useExplain } from "./hooks/useExplain.js";
|
|
10
|
+
import { useFetcher } from "./hooks/useFetcher.js";
|
|
11
|
+
import { usePrettify } from "./hooks/usePrettify.js";
|
|
12
|
+
import { useSchema } from "./hooks/useSchema.js";
|
|
13
|
+
import { useStorage } from "./hooks/useStorage.js";
|
|
14
|
+
import { EXPLAIN_PLUGIN } from "./plugins/explain.js";
|
|
15
|
+
if (GP2 !== GraphiQLProvider) {
|
|
16
|
+
throw new Error("PACKAGE MANAGEMENT ERROR! The providers don't match up!");
|
|
17
|
+
}
|
|
18
18
|
const checkCss = { width: "1.5rem", display: "inline-block" };
|
|
19
|
-
const check = (
|
|
20
|
-
const nocheck = (
|
|
21
|
-
const Ruru = (props) => {
|
|
22
|
-
const storage =
|
|
19
|
+
const check = _jsx("span", { style: checkCss, children: "\u2714" });
|
|
20
|
+
const nocheck = _jsx("span", { style: checkCss });
|
|
21
|
+
export const Ruru = (props) => {
|
|
22
|
+
const storage = useStorage();
|
|
23
23
|
const explain = storage.get("explain") === "true";
|
|
24
24
|
const verbose = storage.get("verbose") === "true";
|
|
25
25
|
const saveHeaders = storage.get("saveHeaders") === "true";
|
|
26
|
-
const setExplain =
|
|
26
|
+
const setExplain = useCallback((newExplain) => {
|
|
27
27
|
storage.set("explain", newExplain ? "true" : "");
|
|
28
28
|
}, [storage]);
|
|
29
|
-
const { fetcher, explainResults, streamEndpoint } =
|
|
29
|
+
const { fetcher, explainResults, streamEndpoint } = useFetcher(props, {
|
|
30
30
|
explain,
|
|
31
31
|
verbose,
|
|
32
32
|
});
|
|
33
|
-
const [error, setError] =
|
|
34
|
-
const explainHelpers =
|
|
35
|
-
const { schema } =
|
|
36
|
-
const defaultQuery = props.defaultQuery ??
|
|
37
|
-
const
|
|
38
|
-
const explorerPlugin = (0, plugin_explorer_1.useExplorerPlugin)({
|
|
39
|
-
query,
|
|
40
|
-
onEdit: setQuery,
|
|
33
|
+
const [error, setError] = useState(null);
|
|
34
|
+
const explainHelpers = useExplain(storage);
|
|
35
|
+
const { schema } = useSchema(props, fetcher, setError, streamEndpoint);
|
|
36
|
+
const defaultQuery = props.defaultQuery ?? DEFAULT_QUERY;
|
|
37
|
+
const explorerPlugin = makeExplorerPlugin({
|
|
41
38
|
showAttribution: false,
|
|
42
39
|
});
|
|
43
|
-
const plugins =
|
|
44
|
-
return [explorerPlugin,
|
|
40
|
+
const plugins = useMemo(() => {
|
|
41
|
+
return [explorerPlugin, EXPLAIN_PLUGIN];
|
|
45
42
|
}, [explorerPlugin]);
|
|
46
|
-
return (
|
|
43
|
+
return (
|
|
44
|
+
//EditorContextProvider
|
|
45
|
+
_jsx(ExplainContext.Provider, { value: {
|
|
47
46
|
explainHelpers,
|
|
48
47
|
explain,
|
|
49
48
|
setExplain,
|
|
50
49
|
explainResults,
|
|
51
|
-
}, children: (
|
|
50
|
+
}, children: _jsx(GraphiQLProvider, { fetcher: fetcher, schema: schema, defaultQuery: defaultQuery, plugins: plugins, shouldPersistHeaders: saveHeaders, children: _jsx(RuruInner, { storage: storage, editorTheme: props.editorTheme, error: error, setError: setError }) }) }));
|
|
52
51
|
};
|
|
53
|
-
|
|
54
|
-
const RuruInner = (props) => {
|
|
52
|
+
export const RuruInner = (props) => {
|
|
55
53
|
const { storage, editorTheme, error, setError, onEditQuery } = props;
|
|
56
|
-
const prettify =
|
|
57
|
-
const mergeQuery =
|
|
58
|
-
const copyQuery =
|
|
59
|
-
return ((
|
|
54
|
+
const prettify = usePrettify();
|
|
55
|
+
const mergeQuery = useMergeQuery();
|
|
56
|
+
const copyQuery = useCopyQuery();
|
|
57
|
+
return (_jsxs("div", { className: "graphiql-container", style: {
|
|
60
58
|
position: "absolute",
|
|
61
59
|
width: "100%",
|
|
62
60
|
height: "100%",
|
|
63
61
|
display: "flex",
|
|
64
62
|
flexDirection: "column",
|
|
65
63
|
overflow: "hidden",
|
|
66
|
-
}, children: [(
|
|
64
|
+
}, children: [_jsx("div", { style: {
|
|
67
65
|
display: "flex",
|
|
68
66
|
flex: "1 1 100%",
|
|
69
67
|
overflow: "hidden",
|
|
70
68
|
position: "relative",
|
|
71
|
-
}, children: (
|
|
69
|
+
}, children: _jsxs(GraphiQLInterface, { editorTheme: editorTheme ?? "graphiql", onEditQuery: onEditQuery, children: [_jsx(GraphiQL.Logo, { children: _jsx("a", { href: "https://grafast.org/ruru", style: { textDecoration: "none" }, target: "_blank", rel: "noreferrer", children: "Ruru" }) }), _jsxs(GraphiQL.Toolbar, { children: [_jsx(ToolbarButton, { onClick: prettify, label: "Prettify Query (Shift-Ctrl-P)", children: _jsx(PrettifyIcon, { className: "graphiql-toolbar-icon", "aria-hidden": "true" }) }), _jsx(ToolbarButton, { onSelect: mergeQuery, label: "Merge Query (Shift-Ctrl-M)", children: _jsx(MergeIcon, { className: "graphiql-toolbar-icon", "aria-hidden": "true" }) }), _jsx(ToolbarButton, { onClick: copyQuery, label: "Copy query (Shift-Ctrl-C)", children: _jsx(CopyIcon, { className: "graphiql-toolbar-icon", "aria-hidden": "true" }) }), _jsxs(ToolbarMenu, { label: "Options", button: _jsx(ToolbarButton, { label: "Options", children: _jsx(SettingsIcon, { className: "graphiql-toolbar-icon", "aria-hidden": "true" }) }), children: [_jsx(ToolbarMenu.Item, { title: "View the SQL statements that this query invokes", onSelect: () => storage.toggle("explain"), children: _jsxs("span", { children: [storage.get("explain") === "true" ? check : nocheck, "Explain (if supported)"] }) }), _jsx(ToolbarMenu.Item, { title: "Don't hide explain from results", onSelect: () => storage.toggle("verbose"), children: _jsxs("span", { children: [storage.get("verbose") === "true" ? check : nocheck, "Verbose"] }) }), _jsx(ToolbarMenu.Item, { title: "Should we persist the headers to localStorage? Header editor is next to variable editor at the bottom.", onSelect: () => storage.toggle("saveHeaders"), children: _jsxs("span", { children: [storage.get("saveHeaders") === "true" ? check : nocheck, "Save headers"] }) })] })] }), _jsx(GraphiQL.Footer, { children: _jsx(RuruFooter, {}) })] }) }), error ? (_jsx(ErrorPopup, { error: error, onClose: () => setError(null) })) : null] }));
|
|
72
70
|
};
|
|
73
|
-
exports.RuruInner = RuruInner;
|
|
74
71
|
//# sourceMappingURL=ruru.js.map
|