GraphQL

GoNest includes a built-in GraphQL engine with query/mutation resolvers and a playground UI.

Setup

import "github.com/0xfurai/gonest/graphql"

engine := graphql.NewEngine()

engine.Query("cats", func(ctx *graphql.ResolverContext) (any, error) {
    return catsService.FindAll(), nil
})

engine.Mutation("createCat", func(ctx *graphql.ResolverContext) (any, error) {
    return catsService.Create(ctx.Args), nil
})

gqlModule := graphql.NewModule(graphql.Options{
    Path:       "/graphql",
    Playground: true,
}, engine)

Queries

curl -X POST http://localhost:3000/graphql \
  -H 'Content-Type: application/json' \
  -d '{"query":"{ cats }"}'

Mutations

curl -X POST http://localhost:3000/graphql \
  -H 'Content-Type: application/json' \
  -d '{"query":"mutation { createCat }"}'

ResolverContext

FieldDescription
ArgsQuery variables
ContextGoNest request context
Info.FieldNameResolved field name
Info.ParentType”query” or “mutation”

For production GraphQL, integrate with gqlgen for type-safe schema-first development.