grx

Basic net/http integration

Run a grx handler on a standalone net/http listener.

Use this integration when GraphQL has its own listener or when a reverse proxy will route a dedicated public path to it. The schema is covered in Run your first server. This page only shows the HTTP integration.

Create the handler

func newHandler() (http.Handler, error) {
	server, err := grx.NewServer(
	grx.WithSchema(graph.Schema()),
	grx.WithPlaygroundPath("/"),
	)
	if err != nil {
		return nil, err
	}
	return server, nil
}

grx.NewServer returns an http.Handler. The default HTTP transport handles GraphQL JSON requests on /graphql.

Serve it

server, err := newHandler()
if err != nil {
	log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":4000", server))

Run the complete example with:

go run ./examples/basic

Add host middleware

Wrap the handler when you need CORS, authentication, request IDs, tracing, or other host-level policy. See CORS and browsers and HTTP middleware.

Other routers

All integrations mount the same http.Handler. They do not change how the GraphQL schema or resolver methods work.

Edit this page on GitHub

Last updated on

On this page