@@ -6,28 +6,83 @@ import (
66 "net/http"
77)
88
9+ type EditorCursorShape string
10+
11+ const (
12+ Line EditorCursorShape = "line"
13+ Block EditorCursorShape = "block"
14+ Underline EditorCursorShape = "underline"
15+ )
16+
17+ type EditorTheme string
18+
19+ const (
20+ Dark EditorTheme = "dark"
21+ Light EditorTheme = "light"
22+ )
23+
24+ type RequestCredentials string
25+
26+ const (
27+ Omit RequestCredentials = "omit"
28+ Include RequestCredentials = "include"
29+ SameOrigin RequestCredentials = "same-origin"
30+ )
31+
32+ type PlaygroundSettings struct {
33+ EditorCursorShape EditorCursorShape `json:"editor.cursorShape,omitempty"`
34+ EditorFontFamily string `json:"editor.fontFamily,omitempty"`
35+ EditorFontSize float64 `json:"editor.fontSize,omitempty"`
36+ EditorReuseHeaders bool `json:"editor.reuseHeaders,omitempty"`
37+ EditorTheme EditorTheme `json:"editor.theme,omitempty"`
38+ GeneralBetaUpdates bool `json:"general.betaUpdates,omitempty"`
39+ PrettierPrintWidth float64 `json:"prettier.printWidth,omitempty"`
40+ PrettierTabWidth float64 `json:"prettier.tabWidth,omitempty"`
41+ PrettierUseTabs bool `json:"prettier.useTabs,omitempty"`
42+ RequestCredentials RequestCredentials `json:"request.credentials,omitempty"`
43+ RequestGlobalHeaders map [string ]string `json:"request.globalHeaders,omitempty"`
44+ SchemaPollingEnable bool `json:"schema.polling.enable,omitempty"`
45+ SchemaPollingEndpointFilter string `json:"schema.polling.endpointFilter,omitempty"`
46+ SchemaPollingInterval float64 `json:"schema.polling.interval,omitempty"`
47+ SchemaDisableComments bool `json:"schema.disableComments,omitempty"`
48+ TracingHideTracingResponse bool `json:"tracing.hideTracingResponse,omitempty"`
49+ TracingTracingSupported bool `json:"tracing.tracingSupported,omitempty"`
50+ }
51+
952type playgroundData struct {
1053 PlaygroundVersion string
1154 Endpoint string
1255 SubscriptionEndpoint string
1356 SetTitle bool
57+ Settings * PlaygroundSettings
1458}
1559
1660// renderPlayground renders the Playground GUI
17- func renderPlayground (w http.ResponseWriter , r * http.Request ) {
61+ func ( h * Handler ) renderPlayground (w http.ResponseWriter , r * http.Request ) {
1862 t := template .New ("Playground" )
1963 t , err := t .Parse (graphcoolPlaygroundTemplate )
2064 if err != nil {
2165 http .Error (w , err .Error (), http .StatusInternalServerError )
2266 return
2367 }
2468
69+ var endpoint string
70+ if h .playground .Endpoint != "" {
71+ // in case the endpoint was explicitly set in the configuration use it here
72+ endpoint = h .playground .Endpoint
73+ } else {
74+ // in case no endpoint was specified assume the graphql api is served under the request's url
75+ endpoint = r .URL .Path
76+ }
77+
2578 d := playgroundData {
2679 PlaygroundVersion : graphcoolPlaygroundVersion ,
27- Endpoint : r . URL . Path ,
80+ Endpoint : endpoint ,
2881 SubscriptionEndpoint : fmt .Sprintf ("ws://%v/subscriptions" , r .Host ),
2982 SetTitle : true ,
83+ Settings : h .playground .Settings ,
3084 }
85+
3186 err = t .ExecuteTemplate (w , "index" , d )
3287 if err != nil {
3388 http .Error (w , err .Error (), http .StatusInternalServerError )
@@ -99,7 +154,8 @@ add "&raw" to the end of the URL within a browser.
99154 // options as 'endpoint' belong here
100155 endpoint: {{ .Endpoint }},
101156 subscriptionEndpoint: {{ .SubscriptionEndpoint }},
102- setTitle: {{ .SetTitle }}
157+ setTitle: {{ .SetTitle }},
158+ settings: {{ .Settings }}
103159 })
104160 })</script>
105161</body>
0 commit comments