- Notifications
You must be signed in to change notification settings - Fork137
Golang HTTP.Handler for graphl-go
License
graphql-go/handler
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Golang HTTP.Handler forgraphl-go
package mainimport ("net/http""github.com/graphql-go/handler")funcmain() {schema,_:= graphql.NewSchema(...)h:= handler.New(&handler.Config{Schema:&schema,Pretty:true,GraphiQL:true,})http.Handle("/graphql",h)http.ListenAndServe(":8080",nil)}
h:=handler.New(&handler.Config{Schema:&schema,Pretty:true,GraphiQL:false,Playground:true,})
The handler will accept requests withthe parameters:
query: A string GraphQL document to be executed.variables: The runtime values to use for any GraphQL query variablesas a JSON object.operationName: If the providedquerycontains multiple namedoperations, this specifies which operation should be executed. If notprovided, an 400 error will be returned if thequerycontains multiplenamed operations.
GraphQL will first look for each parameter in the URL's query-string:
/graphql?query=query+getUser($id:ID){user(id:$id){name}}&variables={"id":"4"}If not found in the query-string, it will look in the POST request body.Thehandler will interpret itdepending on the providedContent-Type header.
application/json: the POST body will be parsed as a JSONobject of parameters.application/x-www-form-urlencoded: this POST body will beparsed as a url-encoded string of key-value pairs.application/graphql: The POST body will be parsed as GraphQLquery string, which provides thequeryparameter.
$ go get github.com/graphql-go/handler$ go build&& gotest ./...
About
Golang HTTP.Handler for graphl-go
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.