Skip to content

Commit

Permalink
rename to runtime from referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
mayakoneval committed Mar 9, 2023
1 parent 8a7c1d3 commit ec62169
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@ const apolloServerVersion = '@apollo/server@4.0.0';

describe('Embedded Explorer Landing Page Config HTML', () => {
it('with document, variables, headers and displayOptions provided', () => {
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions =
{
includeCookies: true,
document: 'query Test { id }',
variables: {
option: {
a: 'val',
b: 1,
c: true,
},
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions & {
runtime: string;
} = {
includeCookies: true,
document: 'query Test { id }',
variables: {
option: {
a: 'val',
b: 1,
c: true,
},
headers: { authorization: 'true' },
embed: {
displayOptions: {
showHeadersAndEnvVars: true,
docsPanelState: 'open',
theme: 'light',
},
persistExplorerState: true,
},
headers: { authorization: 'true' },
embed: {
displayOptions: {
showHeadersAndEnvVars: true,
docsPanelState: 'open',
theme: 'light',
},
graphRef: 'graph@current',
};
persistExplorerState: true,
},
graphRef: 'graph@current',
runtime: '@apollo/server@4.0.0',
};
expect(getEmbeddedExplorerHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
Expand All @@ -49,11 +51,11 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
id="embeddableExplorer"
>
</div>
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?referrer=@apollo/server@4.0.0">
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?runtime=@apollo/server@4.0.0">
</script>
<script>
var endpointUrl = window.location.href;
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"document":"query Test { id }","headers":{"authorization":"true"},"variables":{"option":{"a":"val","b":1,"c":true}},"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true,"includeCookies":true};
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"document":"query Test { id }","headers":{"authorization":"true"},"variables":{"option":{"a":"val","b":1,"c":true}},"displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true,"includeCookies":true,"runtime":"@apollo/server@4.0.0"};
new window.EmbeddedExplorer({
...embeddedExplorerConfig,
endpointUrl,
Expand All @@ -63,12 +65,14 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
});

it('for embedded explorer with document, variables, headers and displayOptions excluded', () => {
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions =
{
includeCookies: false,
embed: true as true,
graphRef: 'graph@current',
};
const config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions & {
runtime: string;
} = {
includeCookies: false,
embed: true as true,
graphRef: 'graph@current',
runtime: '@apollo/server@4.0.0',
};
expect(getEmbeddedExplorerHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
<div class="fallback">
Expand All @@ -88,11 +92,11 @@ describe('Embedded Explorer Landing Page Config HTML', () => {
id="embeddableExplorer"
>
</div>
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?referrer=@apollo/server@4.0.0">
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js?runtime=@apollo/server@4.0.0">
</script>
<script>
var endpointUrl = window.location.href;
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"displayOptions":{}},"persistExplorerState":false,"includeCookies":false};
var embeddedExplorerConfig = {"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"displayOptions":{}},"persistExplorerState":false,"includeCookies":false,"runtime":"@apollo/server@4.0.0"};
new window.EmbeddedExplorer({
...embeddedExplorerConfig,
endpointUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const apolloServerVersion = '@apollo/server@4.0.0';

describe('Landing Page Config HTML', () => {
it('for embedded sandbox with document, variables and headers provided', () => {
const config: LandingPageConfig = {
const config: LandingPageConfig & { runtime: string } = {
includeCookies: true,
document: 'query Test { id }',
variables: {
Expand All @@ -20,6 +20,7 @@ describe('Landing Page Config HTML', () => {
},
headers: { authorization: 'true' },
embed: true,
runtime: '@apollo/server@4.0.0',
};
expect(getEmbeddedSandboxHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
Expand All @@ -40,7 +41,7 @@ describe('Landing Page Config HTML', () => {
id="embeddableSandbox"
>
</div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?referrer=@apollo/server@4.0.0">
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?runtime=@apollo/server@4.0.0">
</script>
<script>
var initialEndpoint = window.location.href;
Expand All @@ -49,15 +50,17 @@ describe('Landing Page Config HTML', () => {
initialEndpoint,
initialState: {"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"},"includeCookies":true},
hideCookieToggle: false,
runtime: '@apollo/server@4.0.0'
});
</script>
`);
});

it('for embedded sandbox with document, variables and headers excluded', () => {
const config: LandingPageConfig = {
const config: LandingPageConfig & { runtime: string } = {
includeCookies: false,
embed: true,
runtime: '@apollo/server@4.0.0',
};
expect(getEmbeddedSandboxHTML(cdnVersion, config, apolloServerVersion))
.toMatchInlineSnapshot(`
Expand All @@ -78,7 +81,7 @@ describe('Landing Page Config HTML', () => {
id="embeddableSandbox"
>
</div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?referrer=@apollo/server@4.0.0">
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js?runtime=@apollo/server@4.0.0">
</script>
<script>
var initialEndpoint = window.location.href;
Expand All @@ -87,6 +90,7 @@ describe('Landing Page Config HTML', () => {
initialEndpoint,
initialState: {"includeCookies":false},
hideCookieToggle: false,
runtime: '@apollo/server@4.0.0'
});
</script>
`);
Expand Down
44 changes: 25 additions & 19 deletions packages/server/src/plugin/landingPage/default/getEmbeddedHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ function getConfigStringForHtml(config: LandingPageConfig) {

export const getEmbeddedExplorerHTML = (
explorerCdnVersion: string,
config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions,
config: ApolloServerPluginEmbeddedLandingPageProductionDefaultOptions & {
runtime: string;
},
apolloServerVersion: string,
) => {
interface EmbeddableExplorerOptions {
Expand Down Expand Up @@ -50,22 +52,25 @@ export const getEmbeddedExplorerHTML = (
persistExplorerState: false,
...(typeof config.embed === 'boolean' ? {} : config.embed),
};
const embeddedExplorerParams: Omit<EmbeddableExplorerOptions, 'endpointUrl'> =
{
graphRef: config.graphRef,
target: '#embeddableExplorer',
initialState: {
document: config.document,
headers: config.headers,
variables: config.variables,
displayOptions: {
...productionLandingPageConfigOrDefault.displayOptions,
},
const embeddedExplorerParams: Omit<
EmbeddableExplorerOptions,
'endpointUrl'
> & { runtime: string } = {
graphRef: config.graphRef,
target: '#embeddableExplorer',
initialState: {
document: config.document,
headers: config.headers,
variables: config.variables,
displayOptions: {
...productionLandingPageConfigOrDefault.displayOptions,
},
persistExplorerState:
productionLandingPageConfigOrDefault.persistExplorerState,
includeCookies: config.includeCookies,
};
},
persistExplorerState:
productionLandingPageConfigOrDefault.persistExplorerState,
includeCookies: config.includeCookies,
runtime: config.runtime,
};

return `
<div class="fallback">
Expand All @@ -81,7 +86,7 @@ export const getEmbeddedExplorerHTML = (
style="width: 100vw; height: 100vh; position: absolute; top: 0;"
id="embeddableExplorer"
></div>
<script src="https://embeddable-explorer.cdn.apollographql.com/${explorerCdnVersion}/embeddable-explorer.umd.production.min.js?referrer=${apolloServerVersion}"></script>
<script src="https://embeddable-explorer.cdn.apollographql.com/${explorerCdnVersion}/embeddable-explorer.umd.production.min.js?runtime=${apolloServerVersion}"></script>
<script>
var endpointUrl = window.location.href;
var embeddedExplorerConfig = ${getConfigStringForHtml(
Expand All @@ -97,7 +102,7 @@ id="embeddableExplorer"

export const getEmbeddedSandboxHTML = (
sandboxCdnVersion: string,
config: LandingPageConfig,
config: LandingPageConfig & { runtime: string },
apolloServerVersion: string,
) => {
return `
Expand All @@ -114,7 +119,7 @@ export const getEmbeddedSandboxHTML = (
style="width: 100vw; height: 100vh; position: absolute; top: 0;"
id="embeddableSandbox"
></div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/${sandboxCdnVersion}/embeddable-sandbox.umd.production.min.js?referrer=${apolloServerVersion}"></script>
<script src="https://embeddable-sandbox.cdn.apollographql.com/${sandboxCdnVersion}/embeddable-sandbox.umd.production.min.js?runtime=${apolloServerVersion}"></script>
<script>
var initialEndpoint = window.location.href;
new window.EmbeddedSandbox({
Expand All @@ -127,6 +132,7 @@ id="embeddableSandbox"
includeCookies: config.includeCookies,
})},
hideCookieToggle: false,
runtime: '${config.runtime}'
});
</script>
`;
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/plugin/landingPage/default/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getNonEmbeddedLandingPageHTML = (
<p>The full landing page cannot be loaded; it appears that you might be offline.</p>
</div>
<script>window.landingPage = ${encodedConfig};</script>
<script src="https://apollo-server-landing-page.cdn.apollographql.com/${cdnVersion}/static/js/main.js?referrer=${apolloServerVersion}"></script>`;
<script src="https://apollo-server-landing-page.cdn.apollographql.com/${cdnVersion}/static/js/main.js?runtime=${apolloServerVersion}"></script>`;
};

// Helper for the two actual plugin functions.
Expand All @@ -85,7 +85,7 @@ function ApolloServerPluginLandingPageDefault<TContext extends BaseContext>(
const apolloServerVersion = `@apollo/server@${packageVersion}`;
const configWithVersion = {
...config,
referrer: apolloServerVersion,
runtime: apolloServerVersion,
};

return {
Expand Down

0 comments on commit ec62169

Please sign in to comment.