@@ -13,6 +13,7 @@ import Playground, {
1313 getSessionsState ,
1414 saveFile ,
1515 newFileTab ,
16+ getEndpoint ,
1617} from 'graphql-playground-react'
1718import {
1819 getGraphQLConfig ,
@@ -32,6 +33,8 @@ import { patchEndpointsToConfigData as patchPrismaEndpointsToConfigData } from '
3233import { patchEndpointsToConfigData } from 'graphql-config-extension-graphcool'
3334import { connect } from 'react-redux'
3435import { errify } from '../utils/errify'
36+ import { createStructuredSelector } from 'reselect'
37+ import * as dotenv from 'dotenv'
3538
3639// import { PermissionSession } from 'graphql-playground/lib/types'
3740
@@ -84,9 +87,10 @@ interface ReduxProps {
8487 selectPrevTab : ( ) => void
8588 closeSelectedTab : ( ) => void
8689 fetchSchema : ( ) => void
87- newSession : ( ) => void
90+ newSession : ( endpoint : string ) => void
8891 saveFile : ( ) => void
8992 newFileTab : ( fileName : string , filePath : string , file : string ) => void
93+ endpoint : string
9094}
9195
9296class App extends React . Component < ReduxProps , State > {
@@ -129,17 +133,18 @@ class App extends React.Component<ReduxProps, State> {
129133 handleSelectFolder = async ( folderPath : string ) => {
130134 try {
131135 // Get config from folderPath
136+ dotenv . config ( { path : folderPath } )
132137 const configPath = findGraphQLConfigFile ( folderPath )
133138 const configString = fs . readFileSync ( configPath , 'utf-8' )
134139
135140 /* 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+ // }
143148
144149 const configDir = path . dirname ( configPath )
145150 let config = await patchEndpointsToConfigData (
@@ -193,7 +198,7 @@ cd ${folderPath}; graphql playground`)
193198 }
194199
195200 newTab = ( ) => {
196- this . props . newSession ( )
201+ this . props . newSession ( this . props . endpoint )
197202 }
198203
199204 closeTab = ( ) => {
@@ -214,7 +219,12 @@ cd ${folderPath}; graphql playground`)
214219 window . addEventListener ( 'keydown' , this . handleKeyDown , true )
215220 this . consumeEvents ( )
216221 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+ ) {
218228 const workspace = this . deserializeWorkspace ( )
219229 if ( workspace ) {
220230 this . setState ( workspace )
@@ -535,7 +545,11 @@ cd ${folderPath}; graphql playground`)
535545 this . newTab ( )
536546 break
537547 case 'Close' :
538- this . closeTab ( )
548+ if ( ! this . state . endpoint && ! this . state . config ) {
549+ ipcRenderer . send ( 'CloseWindow' )
550+ } else {
551+ this . closeTab ( )
552+ }
539553 break
540554 case 'Settings' :
541555 this . openSettingsTab ( )
@@ -610,7 +624,11 @@ cd ${folderPath}; graphql playground`)
610624 }
611625}
612626
613- export default connect ( null , {
627+ const mapStateToProps = createStructuredSelector ( {
628+ endpoint : getEndpoint ,
629+ } )
630+
631+ export default connect ( mapStateToProps , {
614632 openSettingsTab,
615633 selectNextTab,
616634 selectPrevTab,
0 commit comments