New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NEBULA-1385: Add initialState to embedable sandbox based on config #6628
Changes from 6 commits
e347e53
0df5c73
c3d22e4
60ebbc3
62019bc
719587c
6a7d5a0
30ed632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -106,6 +106,52 @@ By default, the landing page displays a footer that links to the documentation t | |||||
<tr> | ||||||
<td> | ||||||
|
||||||
###### `document` | ||||||
|
||||||
`string` | ||||||
</td> | ||||||
<td> | ||||||
|
||||||
A GraphQL document (eg, query or mutation) to populate in the Studio Explorer's editor on load. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still want to add this? This API applies to both sandbox and explorer, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the local dev docs, so they will only ever lead to sandbox afaict There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no strong opinion tho! |
||||||
|
||||||
If you omit this, the Explorer initially loads an example query based on your schema. | ||||||
|
||||||
</td> | ||||||
</tr> | ||||||
|
||||||
<tr> | ||||||
<td> | ||||||
|
||||||
###### `variables` | ||||||
|
||||||
`Record<string, string | Record>` | ||||||
</td> | ||||||
<td> | ||||||
|
||||||
An object containing initial variable values to populate in the Explorer on load. | ||||||
|
||||||
If provided, these variables should apply to the initial query you provide in `document`. | ||||||
|
||||||
</td> | ||||||
</tr> | ||||||
|
||||||
<tr> | ||||||
<td> | ||||||
|
||||||
###### `headers` | ||||||
|
||||||
`Record<string, string>` | ||||||
</td> | ||||||
<td> | ||||||
|
||||||
An object containing initial HTTP header values to populate in the Explorer on load. | ||||||
|
||||||
</td> | ||||||
</tr> | ||||||
|
||||||
<tr> | ||||||
<td> | ||||||
|
||||||
###### `includeCookies` | ||||||
|
||||||
`boolean` | ||||||
|
@@ -228,7 +274,7 @@ If you omit this, the Explorer initially loads an example query based on your sc | |||||
|
||||||
###### `variables` | ||||||
|
||||||
`Record<string, string>` | ||||||
`Record<string, string | Record>` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the right hand side here should just be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ticket was for a new config (initialState) recently added to the embedded-explorer repo. These parameters (document, variables and headers) already existed, but yeah they weren't used or passed through for embedded Sandbox. The parameters were added and the docs were updated accordingly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this change in #6656 |
||||||
</td> | ||||||
<td> | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import { | ||
trevor-scheer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getEmbeddedExplorerHTML, | ||
getEmbeddedSandboxHTML, | ||
} from '../plugin/landingPage/default/index'; | ||
|
||
const version = '_latest'; | ||
|
||
describe('Landing Page Config HTML', () => { | ||
it('for embedded explorer with document, variables, headers and displayOptions provided', () => { | ||
const config = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you define |
||
includeCookies: true, | ||
document: 'query Test { id }', | ||
variables: { | ||
option: { | ||
a: 'val', | ||
b: 1, | ||
c: true, | ||
}, | ||
}, | ||
headers: { authorization: 'true' }, | ||
embed: { | ||
displayOptions: { | ||
showHeadersAndEnvVars: true, | ||
docsPanelState: 'open' as 'open', | ||
theme: 'light' as 'light', | ||
}, | ||
persistExplorerState: true, | ||
}, | ||
graphRef: 'graph@current', | ||
}; | ||
const expected = ` | ||
<style> | ||
iframe { | ||
background-color: white; | ||
} | ||
</style> | ||
<div | ||
style="width: 100vw; height: 100vh; position: absolute; top: 0;" | ||
id="embeddableExplorer" | ||
></div> | ||
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js"></script> | ||
<script> | ||
var endpointUrl = window.location.href; | ||
var embeddedExplorerConfig = {"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},"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"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},"graphRef":"graph@current","displayOptions":{"showHeadersAndEnvVars":true,"docsPanelState":"open","theme":"light"}},"persistExplorerState":true}; | ||
new window.EmbeddedExplorer({ | ||
...embeddedExplorerConfig, | ||
endpointUrl, | ||
}); | ||
</script> | ||
`; | ||
const htmlString = getEmbeddedExplorerHTML(version, config); | ||
expect(htmlString).toEqual(expected); | ||
trevor-scheer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
it('for embedded explorer with document, variables, headers and displayOptions excluded', () => { | ||
const config = { | ||
includeCookies: false, | ||
embed: true as true, | ||
graphRef: 'graph@current', | ||
}; | ||
const expected = ` | ||
<style> | ||
iframe { | ||
background-color: white; | ||
} | ||
</style> | ||
<div | ||
style="width: 100vw; height: 100vh; position: absolute; top: 0;" | ||
id="embeddableExplorer" | ||
></div> | ||
<script src="https://embeddable-explorer.cdn.apollographql.com/_latest/embeddable-explorer.umd.production.min.js"></script> | ||
<script> | ||
var endpointUrl = window.location.href; | ||
var embeddedExplorerConfig = {"includeCookies":false,"embed":true,"graphRef":"graph@current","target":"#embeddableExplorer","initialState":{"includeCookies":false,"embed":true,"graphRef":"graph@current","displayOptions":{}},"persistExplorerState":false}; | ||
new window.EmbeddedExplorer({ | ||
...embeddedExplorerConfig, | ||
endpointUrl, | ||
}); | ||
</script> | ||
`; | ||
const htmlString = getEmbeddedExplorerHTML(version, config); | ||
expect(htmlString).toEqual(expected); | ||
}); | ||
|
||
it('for embedded sandbox with document, variables and headers provided', () => { | ||
const config = { | ||
includeCookies: true, | ||
document: 'query Test { id }', | ||
variables: { | ||
option: { | ||
a: 'val', | ||
b: 1, | ||
c: true, | ||
}, | ||
}, | ||
headers: { authorization: 'true' }, | ||
displayOptions: { | ||
showHeadersAndEnvVariables: true, | ||
docsPanelState: 'open', | ||
theme: 'light', | ||
}, | ||
embed: true as true, | ||
}; | ||
const expected = ` | ||
<style> | ||
iframe { | ||
background-color: white; | ||
} | ||
</style> | ||
<div | ||
style="width: 100vw; height: 100vh; position: absolute; top: 0;" | ||
id="embeddableSandbox" | ||
></div> | ||
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script> | ||
<script> | ||
var initialEndpoint = window.location.href; | ||
new window.EmbeddedSandbox({ | ||
target: '#embeddableSandbox', | ||
initialEndpoint, | ||
includeCookies: true, | ||
initialState: {"document":"query Test { id }","variables":{"option":{"a":"val","b":1,"c":true}},"headers":{"authorization":"true"}}, | ||
}); | ||
</script> | ||
`; | ||
const htmlString = getEmbeddedSandboxHTML(version, config); | ||
expect(htmlString).toEqual(expected); | ||
}); | ||
|
||
it('for embedded sandbox with document, variables and headers excluded', () => { | ||
const config = { | ||
includeCookies: false, | ||
embed: true as true, | ||
}; | ||
const expected = ` | ||
<style> | ||
iframe { | ||
background-color: white; | ||
} | ||
</style> | ||
<div | ||
style="width: 100vw; height: 100vh; position: absolute; top: 0;" | ||
id="embeddableSandbox" | ||
></div> | ||
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script> | ||
<script> | ||
var initialEndpoint = window.location.href; | ||
new window.EmbeddedSandbox({ | ||
target: '#embeddableSandbox', | ||
initialEndpoint, | ||
includeCookies: false, | ||
initialState: {}, | ||
}); | ||
</script> | ||
`; | ||
const htmlString = getEmbeddedSandboxHTML(version, config); | ||
expect(htmlString).toEqual(expected); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these get passed through to sandbox in the regular landing page? We were just missing them before but they are supported right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup! they were always in
ApolloServerPluginLandingPageDefaultBaseOptions
, but just not mentioned in the docs