Skip to content

Commit 669c442

Browse files
committed
added map of graphiql options to lab in render-laboratory
1 parent ce3d72b commit 669c442

File tree

1 file changed

+30
-1
lines changed
  • packages/libraries/render-laboratory/src

1 file changed

+30
-1
lines changed

packages/libraries/render-laboratory/src/index.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { GraphiQLOptions } from 'graphql-yoga';
2+
import type { LaboratoryProps } from '@graphql-hive/laboratory';
23
import {
34
editorWorkerService,
45
favicon,
@@ -9,6 +10,31 @@ import {
910
typescriptWorker,
1011
} from './laboratory.js';
1112

13+
const mapGraphiQLOptionsToLaboratoryProps = (opts?: GraphiQLOptions): LaboratoryProps => {
14+
if (!opts) {
15+
return {};
16+
}
17+
18+
return {
19+
defaultSettings: {
20+
fetch: {
21+
credentials: opts.credentials ?? 'same-origin',
22+
timeout: opts.timeout,
23+
retry: opts.retry,
24+
useGETForQueries: opts.useGETForQueries,
25+
},
26+
subscriptions: {
27+
protocol: opts.subscriptionsProtocol ?? 'WS',
28+
},
29+
introspection: {
30+
queryName: opts.introspectionQueryName,
31+
method: opts.method,
32+
schemaDescription: opts.schemaDescription,
33+
},
34+
},
35+
} satisfies LaboratoryProps;
36+
};
37+
1238
export const renderLaboratory = (opts?: GraphiQLOptions) => /* HTML */ `
1339
<!doctype html>
1440
<html lang="en">
@@ -63,7 +89,10 @@ export const renderLaboratory = (opts?: GraphiQLOptions) => /* HTML */ `
6389
6490
${js};
6591
66-
HiveLaboratory.renderLaboratory(window.document.querySelector('#root'));
92+
HiveLaboratory.renderLaboratory(
93+
window.document.querySelector('#root'),
94+
${JSON.stringify(mapGraphiQLOptionsToLaboratoryProps(opts))},
95+
);
6796
</script>
6897
</body>
6998
</html>

0 commit comments

Comments
 (0)