graphiql

package module
v0.0.0-...-cef5a61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2016 License: MIT Imports: 4 Imported by: 6

README

go-graphiql

Go http handler to serve the graphiql in-browser IDE.

package main

import (
	"net/http"

	"github.com/mnmtanish/go-graphiql"
)

func main() {
	http.HandleFunc("/graphql", myGraphQLHandler)
	http.HandleFunc("/", graphiql.ServeGraphiQL)
	http.ListenAndServe(":9001", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Content = []byte(`
<!DOCTYPE html>
<head>
  <style>body {height: 100vh; margin: 0; width: 100%; overflow: hidden;}</style>
  <link rel="stylesheet" href="//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.css" />
  <link rel="stylesheet" href="//cdn.jsdelivr.net/graphiql/0.6.3/graphiql.css" />
  <script src="//cdn.jsdelivr.net/sweetalert/1.1.3/sweetalert.min.js"></script>
  <script src="//cdn.jsdelivr.net/fetch/0.9.0/fetch.min.js"></script>
  <script src="//cdn.jsdelivr.net/react/0.14.7/react.min.js"></script>
  <script src="//cdn.jsdelivr.net/react/0.14.7/react-dom.min.js"></script>
  <script src="//cdn.jsdelivr.net/graphiql/0.6.3/graphiql.min.js"></script>
  <script>
    (function () {
      var PROMPT_OPTIONS = {
        title: "GraphQL Endpoint",
        text: "Please give the GraphQL HTTP Endpoint",
        type: "input",
        showCancelButton: false,
        inputPlaceholder: window.location.origin + '/graphql',
      };
      document.addEventListener('DOMContentLoaded', function () {
        swal(PROMPT_OPTIONS, function(endpoint){
          if (!endpoint) {
            endpoint = window.location.origin + '/graphql';
          }
          function fetcher(params) {
            var options = {
              method: 'post',
              headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
              body: JSON.stringify(params),
              credentials: 'include',
            };
            return fetch(endpoint, options)
              .then(function (res) { return res.json() });
          }
          var body = React.createElement(GraphiQL, {fetcher: fetcher, query: '', variables: ''});
          ReactDOM.render(body, document.body);
        });
      });
    }());
  </script>
</head>
<body>
</body>
`)

Content ...

Functions

func ServeGraphiQL

func ServeGraphiQL(res http.ResponseWriter, req *http.Request)

ServeGraphiQL is a handler function for HTTP servers

Types

type Client

type Client struct {
	Endpoint string
	Header   http.Header
	Client   http.Client
}

Client ...

func NewClient

func NewClient(uri string) (c *Client, err error)

NewClient ...

func (*Client) Send

func (c *Client) Send(req *Request) (res *Response, err error)

Send ...

type GraphQLError

type GraphQLError struct {
	Message string `json:"message"`
}

GraphQLError ...

func (*GraphQLError) Error

func (e *GraphQLError) Error() string

GraphQLError implements error interface

type Request

type Request struct {
	Query string `json:"query"`
}

Request ...

type Response

type Response struct {
	Data   *json.RawMessage `json:"data"`
	Errors []GraphQLError   `json:"errors,omitempty"`
}

Response ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL