Skip to content

Commit

Permalink
♻️ test had return
Browse files Browse the repository at this point in the history
  • Loading branch information
pugovok committed Jun 24, 2020
1 parent e925b16 commit b844a94
Show file tree
Hide file tree
Showing 5 changed files with 729 additions and 3 deletions.
65 changes: 65 additions & 0 deletions example/starwars/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"log"
"net/http"

"github.com/tribunadigital/graphql-go"
"github.com/tribunadigital/graphql-go/example/starwars"
"github.com/tribunadigital/graphql-go/relay"
)

var schema *graphql.Schema

func init() {
schema = graphql.MustParseSchema(starwars.Schema, &starwars.Resolver{})
}

func main() {
http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(page)
}))

http.Handle("/query", &relay.Handler{Schema: schema})

log.Fatal(http.ListenAndServe(":8080", nil))
}

var page = []byte(`
<!DOCTYPE html>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.11/graphiql.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/2.0.3/fetch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/graphiql/0.11.11/graphiql.min.js"></script>
</head>
<body style="width: 100%; height: 100%; margin: 0; overflow: hidden;">
<div id="graphiql" style="height: 100vh;">Loading...</div>
<script>
function graphQLFetcher(graphQLParams) {
return fetch("/query", {
method: "post",
body: JSON.stringify(graphQLParams),
credentials: "include",
}).then(function (response) {
return response.text();
}).then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
}
ReactDOM.render(
React.createElement(GraphiQL, {fetcher: graphQLFetcher}),
document.getElementById("graphiql")
);
</script>
</body>
</html>
`)
Loading

0 comments on commit b844a94

Please sign in to comment.