@@ -13,6 +13,7 @@ import Playground, {
13
13
getSessionsState ,
14
14
saveFile ,
15
15
newFileTab ,
16
+ getEndpoint ,
16
17
} from 'graphql-playground-react'
17
18
import {
18
19
getGraphQLConfig ,
@@ -32,6 +33,8 @@ import { patchEndpointsToConfigData as patchPrismaEndpointsToConfigData } from '
32
33
import { patchEndpointsToConfigData } from 'graphql-config-extension-graphcool'
33
34
import { connect } from 'react-redux'
34
35
import { errify } from '../utils/errify'
36
+ import { createStructuredSelector } from 'reselect'
37
+ import * as dotenv from 'dotenv'
35
38
36
39
// import { PermissionSession } from 'graphql-playground/lib/types'
37
40
@@ -84,9 +87,10 @@ interface ReduxProps {
84
87
selectPrevTab : ( ) => void
85
88
closeSelectedTab : ( ) => void
86
89
fetchSchema : ( ) => void
87
- newSession : ( ) => void
90
+ newSession : ( endpoint : string ) => void
88
91
saveFile : ( ) => void
89
92
newFileTab : ( fileName : string , filePath : string , file : string ) => void
93
+ endpoint : string
90
94
}
91
95
92
96
class App extends React . Component < ReduxProps , State > {
@@ -129,17 +133,18 @@ class App extends React.Component<ReduxProps, State> {
129
133
handleSelectFolder = async ( folderPath : string ) => {
130
134
try {
131
135
// Get config from folderPath
136
+ dotenv . config ( { path : folderPath } )
132
137
const configPath = findGraphQLConfigFile ( folderPath )
133
138
const configString = fs . readFileSync ( configPath , 'utf-8' )
134
139
135
140
/* tslint:disable-next-line */
136
- if ( configString . includes ( '${env:' ) ) {
137
- errify ( `You opened a .graphqlconfig file that includes environment variables.
138
- In order to use environment variables in the Playground, please start it from the graphql cli. Install with
139
- npm install -g graphql-cli
140
- Then open the graphql config with:
141
- cd ${ folderPath } ; graphql playground` )
142
- }
141
+ // if (configString.includes('${env:')) {
142
+ // errify(`You opened a .graphqlconfig file that includes environment variables.
143
+ // In order to use environment variables in the Playground, please start it from the graphql cli. Install with
144
+ // npm install -g graphql-cli
145
+ // Then open the graphql config with:
146
+ // cd ${folderPath}; graphql playground`)
147
+ // }
143
148
144
149
const configDir = path . dirname ( configPath )
145
150
let config = await patchEndpointsToConfigData (
@@ -193,7 +198,7 @@ cd ${folderPath}; graphql playground`)
193
198
}
194
199
195
200
newTab = ( ) => {
196
- this . props . newSession ( )
201
+ this . props . newSession ( this . props . endpoint )
197
202
}
198
203
199
204
closeTab = ( ) => {
@@ -214,7 +219,12 @@ cd ${folderPath}; graphql playground`)
214
219
window . addEventListener ( 'keydown' , this . handleKeyDown , true )
215
220
this . consumeEvents ( )
216
221
ipcRenderer . send ( 'ready' , '' )
217
- if ( ! this . state . endpoint && ! this . state . config && ! this . state . configPath && ! this . state . configString ) {
222
+ if (
223
+ ! this . state . endpoint &&
224
+ ! this . state . config &&
225
+ ! this . state . configPath &&
226
+ ! this . state . configString
227
+ ) {
218
228
const workspace = this . deserializeWorkspace ( )
219
229
if ( workspace ) {
220
230
this . setState ( workspace )
@@ -535,7 +545,11 @@ cd ${folderPath}; graphql playground`)
535
545
this . newTab ( )
536
546
break
537
547
case 'Close' :
538
- this . closeTab ( )
548
+ if ( ! this . state . endpoint && ! this . state . config ) {
549
+ ipcRenderer . send ( 'CloseWindow' )
550
+ } else {
551
+ this . closeTab ( )
552
+ }
539
553
break
540
554
case 'Settings' :
541
555
this . openSettingsTab ( )
@@ -610,7 +624,11 @@ cd ${folderPath}; graphql playground`)
610
624
}
611
625
}
612
626
613
- export default connect ( null , {
627
+ const mapStateToProps = createStructuredSelector ( {
628
+ endpoint : getEndpoint ,
629
+ } )
630
+
631
+ export default connect ( mapStateToProps , {
614
632
openSettingsTab,
615
633
selectNextTab,
616
634
selectPrevTab,
0 commit comments