Skip to content

Commit c4a4d3d

Browse files
committed
add general to top level
1 parent 2bb2a1e commit c4a4d3d

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

packages/graphql-playground-react/src/localDevIndex.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,59 @@ if (process.env.NODE_ENV !== 'production') {
1515
;(window as any)['GraphQLPlayground'] = {
1616
init(element: HTMLElement, options) {
1717
ReactDOM.render(
18-
<MiddlewareApp setTitle={true} showNewWorkspace={false} {...options} />,
18+
<MiddlewareApp
19+
setTitle={true}
20+
showNewWorkspace={false}
21+
{...options}
22+
config={config}
23+
configString={configString}
24+
/>,
1925
element,
2026
)
2127
},
2228
}
29+
30+
const configString = `projects:
31+
app:
32+
schemaPath: "src/schema.graphql"
33+
extensions:
34+
endpoints:
35+
default: "http://localhost:4000"
36+
database:
37+
schemaPath: "src/generated/prisma.graphql"
38+
extensions:
39+
prisma: database/prisma.yml`
40+
41+
const config = {
42+
projects: {
43+
app: {
44+
schemaPath: 'src/schema.graphql',
45+
includes: ['queries/{booking,queries}.graphql'],
46+
extensions: {
47+
endpoints: {
48+
default: 'http://localhost:4000',
49+
},
50+
},
51+
},
52+
prisma: {
53+
schemaPath: 'src/generated/prisma.graphql',
54+
includes: ['database/seed.graphql'],
55+
extensions: {
56+
prisma: 'database/prisma.yml',
57+
'prepare-binding': {
58+
output: 'src/generated/prisma.ts',
59+
generator: 'prisma-ts',
60+
},
61+
endpoints: {
62+
dev: {
63+
url: 'https://eu1.prisma.sh/tim2/prisma-airbnb-example/dev',
64+
headers: {
65+
Authorization:
66+
'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjp7InNlcnZpY2UiOiJwcmlzbWEtYWlyYm5iLWV4YW1wbGVAZGV2Iiwicm9sZXMiOlsiYWRtaW4iXX0sImlhdCI6MTUyMjY4NDkzNiwiZXhwIjoxNTIzMjg5NzM2fQ.1wnkIJrAplDOznjEzLj8sQERL6dcAM0zjqxOGQBXGn0',
67+
},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
}

packages/graphql-playground-react/src/state/general/selectors.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import { createSelector } from 'reselect'
2-
import { getSelectedWorkspace } from '../workspace/reducers'
3-
4-
const makeGeneralSelector = key =>
5-
createSelector([getSelectedWorkspace], state => {
6-
return state.general.get(key)
7-
})
1+
const makeGeneralSelector = key => state => {
2+
return state.general.get(key)
3+
}
84

95
export const getFixedEndpoint = makeGeneralSelector('fixedEndpoint')
106
export const getHistoryOpen = makeGeneralSelector('historyOpen')

packages/graphql-playground-react/src/state/sessions/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const {
2626
openSettingsTab,
2727
schemaFetchingSuccess,
2828
schemaFetchingError,
29+
setEndpointUnreachable,
2930
renewStacks,
3031
runQuery,
3132
prettifyQuery,
@@ -122,6 +123,7 @@ export const {
122123

123124
FETCH_SCHEMA: simpleAction(),
124125
REFETCH_SCHEMA: simpleAction(),
126+
SET_ENDPOINT_UNREACHABLE: simpleAction('endpoint'),
125127
SCHEMA_FETCHING_SUCCESS: (endpoint, tracingSupported) => ({
126128
endpoint,
127129
tracingSupported,

packages/graphql-playground-react/src/state/sessions/fetchingSagas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
setResponseExtensions,
2323
setCurrentQueryStartTime,
2424
setCurrentQueryEndTime,
25+
setEndpointUnreachable,
2526
} from './actions'
2627
import {
2728
getSelectedSession,
@@ -186,6 +187,10 @@ function* runQuerySaga(action) {
186187
time: new Date(),
187188
resultID: cuid(),
188189
})
190+
const errorMessage = extractMessage(error)
191+
if (errorMessage === 'Failed to fetch') {
192+
yield put(setEndpointUnreachable(session.endpoint))
193+
}
189194
yield put(addResponse(selectedWorkspaceId, session.id, response))
190195
yield put(addHistoryItem(session))
191196
}

packages/graphql-playground-react/src/state/sessions/reducers.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,19 @@ const reducer = handleActions(
299299
})
300300
return state.set('sessions', newSessions)
301301
},
302+
SET_ENDPOINT_UNREACHABLE: (state, { payload }) => {
303+
const newSessions = state.get('sessions').map((session, sessionId) => {
304+
if (session.get('endpoint') === payload.endpoint) {
305+
return session.merge(
306+
Map({
307+
endpointUnreachable: true,
308+
}),
309+
)
310+
}
311+
return session
312+
})
313+
return state.set('sessions', newSessions)
314+
},
302315
SCHEMA_FETCHING_ERROR: (state, { payload }) => {
303316
const newSessions = state.get('sessions').map((session, sessionId) => {
304317
if (session.get('endpoint') === payload.endpoint) {

packages/graphql-playground-react/src/state/workspace/deserialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function deserializePersistedState(state) {
1313
selectedWorkspace: state.selectedWorkspace,
1414
settingsString: state.settingsString,
1515
appHistory: deserializeAppHistory(state.appHistory),
16+
general: deserializeGeneral(state.general),
1617
}) as any
1718
}
1819

@@ -24,7 +25,6 @@ function deserializeWorkspaces(workspaces) {
2425
sessions: deserializeSessionsState(workspace.sessions),
2526
sharing: deserializeSharing(workspace.sharing),
2627
history: deserializeHistory(workspace.history),
27-
general: deserializeGeneral(workspace.general),
2828
})
2929
}),
3030
)

packages/graphql-playground-react/src/state/workspace/reducers.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ export class Workspace extends Record({
2525
sessions: makeSessionState(''),
2626
sharing: new SharingState(),
2727
history: OrderedMap(),
28-
general: new GeneralState(),
2928
}) {
3029
docs: DocsState
3130
sessions: SessionState
3231
sharing: SharingState
3332
history: HistoryState
34-
general: GeneralState
3533
}
3634

3735
export const defaultSettings = {
@@ -48,6 +46,7 @@ export const RootState = Record<any>({
4846
settingsString: JSON.stringify(defaultSettings, null, 2),
4947
stateInjected: false,
5048
appHistory: new AppHistory(),
49+
general: new GeneralState(),
5150
})
5251

5352
const workspaceReducers: Reducer<any> = combineReducers({
@@ -91,6 +90,16 @@ export const rootReducer = (state = new RootState(), action) => {
9190
if (action.type === 'SELECT_APP_HISTORY_ITEM') {
9291
return state.set('appHistory', appHistory(state.appHistory, action))
9392
}
93+
const generalActions = {
94+
OPEN_HISTORY: true,
95+
CLOSE_HISTORY: true,
96+
SET_ENDPOINT_DISABLED: true,
97+
SET_CONFIG_STRING: true,
98+
}
99+
100+
if (generalActions[action.type]) {
101+
return state.set('general', general(state.general, action))
102+
}
94103

95104
const selectedWorkspaceId =
96105
action.payload && action.payload.workspaceId
@@ -113,7 +122,6 @@ export function makeWorkspace(endpoint) {
113122
sessions: sessionState,
114123
sharing: new SharingState(),
115124
history: OrderedMap(),
116-
general: new GeneralState(),
117125
}) as any
118126
}
119127

0 commit comments

Comments
 (0)