Skip to content

Commit 771cfc3

Browse files
committed
Restore Apollo Explorer/Sandbox instead of GraphiQL
Just one less variable for now.
1 parent 9d08369 commit 771cfc3

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { stripIndent } from 'common-tags';
2+
import { titleCase } from 'title-case';
3+
4+
interface Options {
5+
graphRef?: string;
6+
[key: string]: any;
7+
}
8+
9+
export const apolloExplorer = (options: Options) => {
10+
const { title, ...config } = options;
11+
const product = config.graphRef ? 'explorer' : 'sandbox';
12+
return stripIndent`
13+
<!DOCTYPE html>
14+
<html lang="en">
15+
<head>
16+
<title>${title}</title>
17+
</head>
18+
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
19+
<div id="sandbox" style="height:100vh; width:100vw;"></div>
20+
<script src="https://embeddable-${product}.cdn.apollographql.com/${
21+
product === 'sandbox' ? '_latest' : 'v3'
22+
}/embeddable-${product}.umd.production.min.js"></script>
23+
<script>
24+
var initialEndpoint = window.location.href;
25+
var config = ${JSON.stringify(config)};
26+
// https://www.apollographql.com/docs/apollo-sandbox
27+
new window.Embedded${titleCase(product)}({
28+
target: '#sandbox',
29+
initialEndpoint,
30+
...config,
31+
});
32+
</script>
33+
</html>
34+
`;
35+
};

src/core/graphql/graphql.options.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { GqlContextType, Session } from '~/common';
1919
import { getRegisteredScalars } from '~/common/scalars';
2020
import { ConfigService } from '../config/config.service';
2121
import { VersionService } from '../config/version.service';
22+
import { apolloExplorer } from './apollo-explorer';
2223
import { isGqlContext } from './gql-context.host';
2324
import { GraphqlTracingPlugin } from './graphql-tracing.plugin';
2425

@@ -41,6 +42,7 @@ export class GraphqlOptions implements GqlOptionsFactory {
4142
if (version.hash) {
4243
process.env.APOLLO_SERVER_USER_VERSION = version.hash;
4344
}
45+
const graphRef = process.env.APOLLO_GRAPH_REF;
4446

4547
const scalars = mapKeys.fromList(
4648
getRegisteredScalars(),
@@ -52,10 +54,20 @@ export class GraphqlOptions implements GqlOptionsFactory {
5254
path: '/graphql/:opName?',
5355
autoSchemaFile: 'schema.graphql',
5456
graphiql: {
55-
title: 'CORD API',
57+
title: graphRef ?? 'CORD@local',
5658
defaultEditorToolsVisibility: false,
5759
credentials: 'include',
5860
},
61+
renderGraphiQL: () =>
62+
apolloExplorer({
63+
title: graphRef ?? 'CORD@local',
64+
graphRef: graphRef,
65+
endpointIsEditable: false,
66+
hideCookieToggle: true,
67+
initialState: {
68+
includeCookies: true,
69+
},
70+
}),
5971
context: this.context,
6072
maskedErrors: false, // Errors are formatted in plugin
6173
sortSchema: true,

0 commit comments

Comments
 (0)