Skip to content

Commit 2c9c160

Browse files
committed
fix(cleanup): Remove platform token, use origin
1 parent f01ca8b commit 2c9c160

File tree

3 files changed

+10
-33
lines changed

3 files changed

+10
-33
lines changed

packages/graphql-playground-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-playground-react",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"main": "./lib/lib.js",
55
"typings": "./lib/lib.d.ts",
66
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration).",

packages/graphql-playground-react/src/components/MiddlewareApp.tsx

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ import * as queryString from 'query-string'
2222

2323
const store = createStore()
2424

25-
function getParameterByName(name: string): string | null {
26-
const url = window.location.href
27-
name = name.replace(/[\[\]]/g, '\\$&')
28-
const regexa = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)')
29-
const results = regexa.exec(url)
30-
if (!results || !results[2]) {
31-
return null
32-
}
33-
return decodeURIComponent(results[2].replace(/\+/g, ' '))
34-
}
35-
3625
export interface Props {
3726
endpoint?: string
3827
endpointUrl?: string
@@ -47,7 +36,6 @@ export interface Props {
4736
onSaveConfig?: (configString: string) => void
4837
onNewWorkspace?: () => void
4938
getRef?: (ref: any) => void
50-
platformToken?: string
5139
session?: any
5240
env?: any
5341
config?: GraphQLConfig
@@ -59,7 +47,6 @@ export interface State {
5947
subscriptionPrefix?: string
6048
subscriptionEndpoint?: string
6149
shareUrl?: string
62-
platformToken?: string
6350
settingsString: string
6451
settings: ISettings
6552
configIsYaml?: boolean
@@ -95,7 +82,10 @@ export default class MiddlewareApp extends React.Component<Props, State> {
9582

9683
let headers
9784
let endpoint =
98-
props.endpoint || props.endpointUrl || params.endpoint || location.href
85+
props.endpoint ||
86+
props.endpointUrl ||
87+
params.endpoint ||
88+
`${location.origin}${location.pathname}`
9989

10090
let subscriptionEndpoint: any =
10191
props.subscriptionEndpoint || params.subscriptionEndpointndpoint
@@ -123,10 +113,6 @@ export default class MiddlewareApp extends React.Component<Props, State> {
123113

124114
this.state = {
125115
endpoint: this.absolutizeUrl(endpoint),
126-
platformToken:
127-
props.platformToken ||
128-
localStorage.getItem('platform-token') ||
129-
undefined,
130116
subscriptionEndpoint,
131117
settingsString,
132118
settings: this.props.settings || this.getSettings(settingsString),
@@ -237,14 +223,6 @@ export default class MiddlewareApp extends React.Component<Props, State> {
237223
return endpoint.replace(/^http/, 'ws')
238224
}
239225

240-
componentWillMount() {
241-
const platformToken = getParameterByName('platform-token')
242-
if (platformToken && platformToken.length > 0) {
243-
localStorage.setItem('platform-token', platformToken)
244-
window.location.replace(window.location.origin + window.location.pathname)
245-
}
246-
}
247-
248226
componentDidMount() {
249227
if (this.state.subscriptionEndpoint === '') {
250228
this.updateSubscriptionsUrl()
@@ -291,7 +269,6 @@ export default class MiddlewareApp extends React.Component<Props, State> {
291269
onChangeSubscriptionsEndpoint={
292270
this.handleChangeSubscriptionsEndpoint
293271
}
294-
adminAuthToken={this.state.platformToken}
295272
settings={this.normalizeSettings(this.state.settings)}
296273
settingsString={this.state.settingsString}
297274
onSaveSettings={this.handleSaveSettings}
@@ -449,10 +426,7 @@ export default class MiddlewareApp extends React.Component<Props, State> {
449426
}
450427

451428
private getTitle() {
452-
if (
453-
this.state.platformToken ||
454-
this.state.endpoint.includes('api.graph.cool')
455-
) {
429+
if (this.state.endpoint.includes('api.graph.cool')) {
456430
const projectId = this.getProjectId(this.state.endpoint)
457431
const cluster = this.state.endpoint.includes('api.graph.cool')
458432
? 'shared'

packages/graphql-playground-react/src/components/Playground.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ export class Playground extends React.PureComponent<Props & DocsState, State> {
251251
}
252252

253253
setApolloLink = (session: Session): ApolloLink => {
254-
if (this.apolloLinks[session.id]) {
254+
if (
255+
this.apolloLinks[session.id] &&
256+
this.apolloLinks[session.id].unsubscribeAll
257+
) {
255258
this.apolloLinks[session.id].unsubscribeAll()
256259
}
257260

0 commit comments

Comments
 (0)