This example shows how to use graphql-go in hertz server.
- Start server
go run main.go
- Test
- Use curl to send a request
curl -X POST 'http://localhost:9090/' --header 'content-type: application/json' --data-raw '{"query":"query{hello}"}'
Result:
> curl -X POST 'http://localhost:9090/' --header 'content-type: application/json' --data-raw '{"query":"query{hello}"}'
{"data":{"hello":"world"}}
curl 'http://localhost:9090/?query=query%7Bhello%7D'
Result:
> curl 'http://localhost:9090/?query=query%7Bhello%7D'
{"data":{"hello":"world"}}
- Use Graphql Playground to send a request to http://localhost:9090/
query {
hello
}
{
"data": {
"hello": "world"
}
}
We do not recommend using gqlgen in hertz. Because adapting the Go standard library http.Handler
and http.HandlerFunc
methods results in a performance hit.