@@ -20,6 +20,7 @@ import (
20
20
const defaultGraphQLPath = "/graphql"
21
21
const defaultGraphQLSchemaPath = "/graphql-schema"
22
22
const defaultRESTPath = "/todo"
23
+ const defaultGraphQLPlaygroundPath = "/graphql-playground"
23
24
24
25
// Environment variables prefixed with "ENDPOINT_" can override settings e.g. "ENDPOINT_HOSTS"
25
26
const envVarPrefix = "endpoint"
@@ -35,7 +36,7 @@ var serverCmd = &cobra.Command{
35
36
// TODO: Validate GraphQL/REST paths, should they be disjointed?
36
37
37
38
hosts := viper .GetStringSlice ("hosts" )
38
- if len (hosts ) == 0 {
39
+ if len (hosts ) == 0 {
39
40
return errors .New ("hosts are required" )
40
41
}
41
42
@@ -118,6 +119,7 @@ func Execute() {
118
119
flags .Bool ("start-graphql" , true , "start the GraphQL endpoint" )
119
120
flags .String ("graphql-path" , defaultGraphQLPath , "path for the GraphQL endpoint" )
120
121
flags .String ("graphql-schema-path" , defaultGraphQLSchemaPath , "path for the GraphQL schema management" )
122
+ flags .String ("graphql-playground-path" , defaultGraphQLPlaygroundPath , "path for the GraphQL playground static file" )
121
123
flags .Int ("graphql-port" , 8080 , "port for the GraphQL endpoint" )
122
124
123
125
// REST specific flags
@@ -171,6 +173,7 @@ func addGraphQLRoutes(router *httprouter.Router, endpoint *endpoint.DataEndpoint
171
173
172
174
singleKeyspace := viper .GetString ("keyspace" )
173
175
rootPath := viper .GetString ("graphql-path" )
176
+ playgroundPath := viper .GetString ("graphql-playground-path" )
174
177
175
178
if singleKeyspace != "" {
176
179
routes , err = endpoint .RoutesKeyspaceGraphQL (rootPath , singleKeyspace )
@@ -187,6 +190,8 @@ func addGraphQLRoutes(router *httprouter.Router, endpoint *endpoint.DataEndpoint
187
190
router .Handler (route .Method , route .Pattern , route .Handler )
188
191
}
189
192
193
+ router .GET (playgroundPath , graphql .GetPlaygroundHandle (rootPath , viper .GetInt ("graphql-port" )))
194
+
190
195
supportedOps := viper .GetStringSlice ("operations" )
191
196
ops , err := config .Ops (supportedOps ... )
192
197
if err != nil {
@@ -234,6 +239,6 @@ func listenAndServe(handler http.Handler, port int, endpointNames string) {
234
239
if err != nil {
235
240
logger .Fatal ("unable to start server" ,
236
241
"port" , port ,
237
- "error" , err , )
242
+ "error" , err )
238
243
}
239
244
}
0 commit comments