Repository navigation
Expand file tree
/
Copy pathGraphQL.tsx
More file actions
72 lines (58 loc) · 1.97 KB
/
Copy pathGraphQL.tsx
File metadata and controls
72 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Box, useColorMode } from '@chakra-ui/react';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import { GraphiQL } from 'graphiql';
import React from 'react';
import config from 'configs/app';
import buildUrl from 'lib/api/buildUrl';
import 'graphiql/graphiql.css';
import isBrowser from 'lib/isBrowser';
const feature = config.features.graphqlApiDocs;
const graphQLStyle = {
'.graphiql-container': {
backgroundColor: 'unset',
},
};
const GraphQL = () => {
const { colorMode } = useColorMode();
const graphqlTheme = window.localStorage.getItem('graphiql:theme');
// colorModeState used as a key to re-render GraphiQL conponent after color mode change
const [ colorModeState, setColorModeState ] = React.useState(graphqlTheme);
React.useEffect(() => {
if (isBrowser()) {
if (graphqlTheme !== colorMode) {
window.localStorage.setItem('graphiql:theme', colorMode);
setColorModeState(colorMode);
}
}
}, [ colorMode, graphqlTheme ]);
if (!feature.isEnabled) {
return null;
}
const initialQuery = `{
transaction(
hash: "${ feature.defaultTxHash }"
) {
hash
blockNumber
value
gasUsed
}
}`;
const graphqlUrl = buildUrl('graphql');
const fetcher = createGraphiQLFetcher({
url: graphqlUrl,
// graphql ws implementation with absinthe plugin is incompatible with graphiql-ws protocol
// or the older one subscriptions-transport-ws
// so we (isstuev & vbaranov) decided to configure playground without subscriptions
// in case of any complaint consider reconfigure the graphql ws server with absinthe_graphql_ws package
// subscriptionUrl: `wss://${config.app.host}/socket/`,
});
return (
<Box h="100vh" overflowX="scroll" sx={ graphQLStyle }>
<Box h="100vh" minW="900px" sx={ graphQLStyle }>
<GraphiQL fetcher={ fetcher } defaultQuery={ initialQuery } key={ colorModeState }/>
</Box>
</Box>
);
};
export default GraphQL;