Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Golang HTTP.Handler for graphl-go

License

NotificationsYou must be signed in to change notification settings

graphql-go/handler

Repository files navigation

Golang HTTP.Handler forgraphl-go

Usage

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)}

Using Playground

h:=handler.New(&handler.Config{Schema:&schema,Pretty:true,GraphiQL:false,Playground:true,})

Details

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 providedquery contains multiple namedoperations, this specifies which operation should be executed. If notprovided, an 400 error will be returned if thequery contains 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 thequery parameter.

Examples

Test

$ go get github.com/graphql-go/handler$ go build&& gotest ./...

About

Golang HTTP.Handler for graphl-go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors16

Languages


[8]ページ先頭

©2009-2025 Movatter.jp