Skip to content

Commit

Permalink
add migration for old sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Dec 2, 2017
1 parent ff848cb commit 273546c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion packages/graphql-playground/src/components/MiddlewareApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function getParameterByName(name: string): string | null {

export interface Props {
endpoint?: string
endpointUrl?: string
subscriptionEndpoint?: string
setTitle?: boolean
settings?: EditorSettings
Expand Down Expand Up @@ -91,7 +92,10 @@ class MiddlewareApp extends React.Component<Props, State> {
const { activeEnv, projectName } = this.getInitialActiveEnv(config)

let endpoint =
props.endpoint || getParameterByName('endpoint') || location.href
props.endpoint ||
props.endpointUrl ||
getParameterByName('endpoint') ||
location.href

let subscriptionEndpoint: string | undefined | null =
props.subscriptionEndpoint || getParameterByName('subscriptionEndpoint')
Expand All @@ -100,6 +104,8 @@ class MiddlewareApp extends React.Component<Props, State> {
const endpoints = getActiveEndpoints(config, activeEnv, projectName)
endpoint = endpoints.endpoint
subscriptionEndpoint = endpoints.subscriptionEndpoint
} else {
subscriptionEndpoint = this.getGraphcoolSubscriptionEndpoint(endpoint)

This comment has been minimized.

Copy link
@sachmata

sachmata Mar 3, 2018

Here subscriptionEndpoint defined in props is completely overridden by endpoint and essentially ignored, is this intentional?

subscriptionEndpoint = this.getGraphcoolSubscriptionEndpoint(subscriptionEndpoint)
}

this.state = {
Expand All @@ -121,6 +127,16 @@ class MiddlewareApp extends React.Component<Props, State> {
}
}

getGraphcoolSubscriptionEndpoint(endpoint) {
if (endpoint.includes('api.graph.cool')) {
return `wss://subscriptions.graph.cool/v1/${
endpoint.split('/').slice(-1)[0]
}`
}

return endpoint
}

migrateSettingsString(settingsString) {
const replacementMap = {
theme: 'editor.theme',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class PlaygroundStorage {
}

// migrate headers to new format
private static runMigration(project, migrationEndpoint?: string) {
private static runMigration(project, migrationEndpoint: string) {
if (!project) {
return project
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class PlaygroundStorage {
date: new Date(item.date),
}))
}
return PlaygroundStorage.runMigration(result)
return PlaygroundStorage.runMigration(result, this.endpoint)
}

private getExecutedQueryCount() {
Expand Down

0 comments on commit 273546c

Please sign in to comment.