@@ -6,28 +6,83 @@ import (
6
6
"net/http"
7
7
)
8
8
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
+
9
52
type playgroundData struct {
10
53
PlaygroundVersion string
11
54
Endpoint string
12
55
SubscriptionEndpoint string
13
56
SetTitle bool
57
+ Settings * PlaygroundSettings
14
58
}
15
59
16
60
// 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 ) {
18
62
t := template .New ("Playground" )
19
63
t , err := t .Parse (graphcoolPlaygroundTemplate )
20
64
if err != nil {
21
65
http .Error (w , err .Error (), http .StatusInternalServerError )
22
66
return
23
67
}
24
68
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
+
25
78
d := playgroundData {
26
79
PlaygroundVersion : graphcoolPlaygroundVersion ,
27
- Endpoint : r . URL . Path ,
80
+ Endpoint : endpoint ,
28
81
SubscriptionEndpoint : fmt .Sprintf ("ws://%v/subscriptions" , r .Host ),
29
82
SetTitle : true ,
83
+ Settings : h .playground .Settings ,
30
84
}
85
+
31
86
err = t .ExecuteTemplate (w , "index" , d )
32
87
if err != nil {
33
88
http .Error (w , err .Error (), http .StatusInternalServerError )
@@ -99,7 +154,8 @@ add "&raw" to the end of the URL within a browser.
99
154
// options as 'endpoint' belong here
100
155
endpoint: {{ .Endpoint }},
101
156
subscriptionEndpoint: {{ .SubscriptionEndpoint }},
102
- setTitle: {{ .SetTitle }}
157
+ setTitle: {{ .SetTitle }},
158
+ settings: {{ .Settings }}
103
159
})
104
160
})</script>
105
161
</body>
0 commit comments