graphqlhandler

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 6 Imported by: 0

README

graphql-handler

HTTP Handler for creating GraphQL servers in Golang

This implementation follow the guidelines for adapting http requests to GraphQL requests from https://graphql.org/learn/serving-over-http/

Usage

  • Create your Golang code for handling web requests
package main

import ghandler "github.com/flaviostutz/graphql-handler"

func main() {
    http.HandleFunc("/graphql", ghandler.NewGraphQLHandler(sampleSchema(), true))
    
	log.Println("Listening on :1234...")
	http.ListenAndServe(":1234", nil)
}
  • Run go run example.go

  • Create a todo item with curl -g 'http://localhost:1234/graphql?query=mutation+_{createTodo(title:"My+new+todo"){title}}'

  • List all todo items with curl -g 'http://localhost:1234/graphql?query={todoList{title}}'

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGraphQLHandler

func NewGraphQLHandler(schema graphql.Schema, debug bool) func(w http.ResponseWriter, r *http.Request)

NewGraphQLHandler creates a new handler

Types

type GraphQLHandler

type GraphQLHandler struct {
	//Schema graphql schema used for handling requests
	Schema graphql.Schema
	//Debug show info and error messages on output log
	Debug bool
}

GraphQLHandler http handler for handling GraphQL requests according to https://graphql.org/learn/serving-over-http/

Jump to

Keyboard shortcuts

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