|
|
@ -3,6 +3,11 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
|
|
|
|
"github.com/graphql-go/handler"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type EventManager struct {
|
|
|
|
type EventManager struct {
|
|
|
@ -11,6 +16,96 @@ type EventManager struct {
|
|
|
|
aborts []chan error
|
|
|
|
aborts []chan error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
graphiql_string := `
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
|
|
|
* Copyright (c) 2021 GraphQL Contributors
|
|
|
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* This source code is licensed under the license found in the
|
|
|
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html lang="en">
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
|
|
|
<title>GraphiQL</title>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
body {
|
|
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#graphiql {
|
|
|
|
|
|
|
|
height: 100vh;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
|
|
|
This GraphiQL example depends on Promise and fetch, which are available in
|
|
|
|
|
|
|
|
modern browsers, but can be "polyfilled" for older browsers.
|
|
|
|
|
|
|
|
GraphiQL itself depends on React DOM.
|
|
|
|
|
|
|
|
If you do not want to rely on a CDN, you can host these files locally or
|
|
|
|
|
|
|
|
include them directly in your favored resource bundler.
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script
|
|
|
|
|
|
|
|
crossorigin
|
|
|
|
|
|
|
|
src="https://unpkg.com/react@18/umd/react.development.js"
|
|
|
|
|
|
|
|
></script>
|
|
|
|
|
|
|
|
<script
|
|
|
|
|
|
|
|
crossorigin
|
|
|
|
|
|
|
|
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"
|
|
|
|
|
|
|
|
></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
|
|
|
These two files can be found in the npm module, however you may wish to
|
|
|
|
|
|
|
|
copy them directly into your environment, or perhaps include them in your
|
|
|
|
|
|
|
|
favored resource bundler.
|
|
|
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
|
|
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<div id="graphiql">Loading...</div>
|
|
|
|
|
|
|
|
<script
|
|
|
|
|
|
|
|
src="https://unpkg.com/graphiql/graphiql.min.js"
|
|
|
|
|
|
|
|
type="application/javascript"
|
|
|
|
|
|
|
|
></script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
|
|
|
|
|
|
|
|
root.render(
|
|
|
|
|
|
|
|
React.createElement(GraphiQL, {
|
|
|
|
|
|
|
|
fetcher: GraphiQL.createFetcher({
|
|
|
|
|
|
|
|
url: 'https://swapi-graphql.netlify.app/.netlify/functions/index',
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
defaultEditorToolsVisibility: true,
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (manager * EventManager) GQL() error {
|
|
|
|
|
|
|
|
rootQuery := graphql.ObjectConfig{Name: "RootQuery", Field: fields}
|
|
|
|
|
|
|
|
schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
|
|
|
|
|
|
|
|
schema, err := graphql.NewSchema(schemaConfig)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h := handler.New(&handler.Config{Schema: &schema, })
|
|
|
|
|
|
|
|
server := http.NewServeMux()
|
|
|
|
|
|
|
|
server.Handle("/graphql", h)
|
|
|
|
|
|
|
|
server.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
|
|
|
|
|
|
w.Header.Set("Content-Type", "text/html; charset=utf-8")
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
|
|
|
io.WriteString(w, graphiql_string)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// root_event's requirements must be in dag_nodes, and dag_nodes must be ordered by dependency(children first)
|
|
|
|
// root_event's requirements must be in dag_nodes, and dag_nodes must be ordered by dependency(children first)
|
|
|
|
func NewEventManager(root_event Event, dag_nodes []Resource) * EventManager {
|
|
|
|
func NewEventManager(root_event Event, dag_nodes []Resource) * EventManager {
|
|
|
|
|
|
|
|
|
|
|
|