1+ <!DOCTYPE html>
2+ < html xmlns:https ="http://www.w3.org/1999/xhtml ">
3+ < head >
4+ < style >
5+ body {
6+ height : 100% ;
7+ margin : 0 ;
8+ width : 100% ;
9+ overflow : hidden;
10+ font-family : "Segoe UI" , "Roboto" , "Noto Sans" , "Ubuntu" , "Droid Sans" , "Helvetica Neue" , sans-serif;
11+ font-size : 14px ;
12+ }
13+
14+ div .welcome {
15+ padding : 10px ;
16+ border-bottom : solid thin black;
17+ }
18+
19+ # graphiql {
20+ height : 100vh ;
21+ }
22+ </ style >
23+
24+ <!--
25+ This GraphiQL example depends on Promise and fetch, which are available in
26+ modern browsers, but can be "polyfilled" for older browsers.
27+ GraphiQL itself depends on React DOM.
28+ If you do not want to rely on a CDN, you can host these files locally or
29+ include them directly in your favored resource bunder.
30+ -->
31+ < script src ="//cdn.jsdelivr.net/es6-promise/4.0.5/es6-promise.auto.min.js "> </ script >
32+ < script src ="//cdn.jsdelivr.net/fetch/0.9.0/fetch.min.js "> </ script >
33+ < script src ="//cdn.jsdelivr.net/react/15.4.2/react.min.js "> </ script >
34+ < script src ="//cdn.jsdelivr.net/react/15.4.2/react-dom.min.js "> </ script >
35+
36+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.5/graphiql.css "/>
37+ < link rel ="stylesheet " href ="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.23.0/theme/solarized.css "/>
38+ < script src ="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.5/graphiql.js "> </ script >
39+ </ head >
40+ < body >
41+ < div class ="welcome ">
42+ < h2 > Welcome to the graphql-java HTTP example.</ h2 >
43+ < span > This is backed by the classic StarWars example schema and embeds
44+ the < a href ="https://github.com/graphql/graphiql "> graphiql</ a > tooling to allow you to fire off queries.
45+ </ span >
46+ </ div >
47+ < div id ="graphiql "> Loading graphiql editor...</ div >
48+ < script >
49+ /**
50+ * This GraphiQL example illustrates how to use some of GraphiQL's props
51+ * in order to enable reading and updating the URL parameters, making
52+ * link sharing of queries a little bit easier.
53+ *
54+ * This is only one example of this kind of feature, GraphiQL exposes
55+ * various React params to enable interesting integrations.
56+ */
57+ // Parse the search string to get url parameters.
58+ var search = window . location . search ;
59+ var parameters = { } ;
60+ search . substr ( 1 ) . split ( '&' ) . forEach ( function ( entry ) {
61+ var eq = entry . indexOf ( '=' ) ;
62+ if ( eq >= 0 ) {
63+ parameters [ decodeURIComponent ( entry . slice ( 0 , eq ) ) ] =
64+ decodeURIComponent ( entry . slice ( eq + 1 ) ) ;
65+ }
66+ } ) ;
67+ // if variables was provided, try to format it.
68+ if ( parameters . variables ) {
69+ try {
70+ parameters . variables =
71+ JSON . stringify ( JSON . parse ( parameters . variables ) , null , 2 ) ;
72+ } catch ( e ) {
73+ // Do nothing, we want to display the invalid JSON as a string, rather
74+ // than present an error.
75+ }
76+ }
77+ // When the query and variables string is edited, update the URL bar so
78+ // that it can be easily shared
79+ function onEditQuery ( newQuery ) {
80+ parameters . query = newQuery ;
81+ updateURL ( ) ;
82+ }
83+
84+ function onEditVariables ( newVariables ) {
85+ parameters . variables = newVariables ;
86+ updateURL ( ) ;
87+ }
88+
89+ function onEditOperationName ( newOperationName ) {
90+ parameters . operationName = newOperationName ;
91+ updateURL ( ) ;
92+ }
93+
94+ function updateURL ( ) {
95+ var newSearch = '?' + Object . keys ( parameters ) . filter ( function ( key ) {
96+ return Boolean ( parameters [ key ] ) ;
97+ } ) . map ( function ( key ) {
98+ return encodeURIComponent ( key ) + '=' +
99+ encodeURIComponent ( parameters [ key ] ) ;
100+ } ) . join ( '&' ) ;
101+ history . replaceState ( null , null , newSearch ) ;
102+ }
103+
104+ // Defines a GraphQL fetcher using the fetch API. You're not required to
105+ // use fetch, and could instead implement graphQLFetcher however you like,
106+ // as long as it returns a Promise or Observable.
107+ function graphQLFetcher ( graphQLParams ) {
108+ // This example expects a GraphQL server at the path /graphql.
109+ // Change this to point wherever you host your GraphQL server.
110+ return fetch ( '/graphql' , {
111+ method : 'post' ,
112+ headers : {
113+ 'Accept' : 'application/json' ,
114+ 'Content-Type' : 'application/json' ,
115+ } ,
116+ body : JSON . stringify ( graphQLParams ) ,
117+ credentials : 'include' ,
118+ } ) . then ( function ( response ) {
119+ return response . text ( ) ;
120+ } ) . then ( function ( responseBody ) {
121+ try {
122+ return JSON . parse ( responseBody ) ;
123+ } catch ( error ) {
124+ return responseBody ;
125+ }
126+ } ) ;
127+ }
128+
129+ // Render <GraphiQL /> into the body.
130+ // See the README in the top level of this module to learn more about
131+ // how you can customize GraphiQL by providing different values or
132+ // additional child elements.
133+ ReactDOM . render (
134+ React . createElement ( GraphiQL , {
135+ fetcher : graphQLFetcher ,
136+ query : parameters . query ,
137+ variables : parameters . variables ,
138+ operationName : parameters . operationName ,
139+ onEditQuery : onEditQuery ,
140+ onEditVariables : onEditVariables ,
141+ onEditOperationName : onEditOperationName ,
142+ editorTheme : "solarized"
143+ } ) ,
144+ document . getElementById ( 'graphiql' )
145+ ) ;
146+ </ script >
147+ </ html >
0 commit comments