Documentation
¶
Overview ¶
Package users is the canonical "owns its data, exposes typed REST" module: a minimal user catalog tagged DeployAs("users-svc") so it can be peeled out into its own binary later.
The Module declaration here is what `nexus gen clients` reads to emit zz_users_client_gen.go alongside this file. Other modules (e.g. checkout) consume `users.UsersClient` instead of touching the in-memory store directly — the codegen makes the local-vs- remote choice transparent at construction time.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Module = nexus.Module("users", nexus.DeployAs("users-svc"), nexus.Provide(NewService), nexus.AsRest("GET", "/users/:id", NewGet), nexus.AsRest("GET", "/users", NewList), nexus.AsQuery(NewSearch), )
Module is the wired declaration. DeployAs("users-svc") is the hint that drives codegen — without it, this module is "always local" and no client stub is emitted.
Functions ¶
This section is empty.
Types ¶
type GetArgs ¶
type GetArgs struct {
ID string `json:"id" uri:"id"`
}
GetArgs binds a path parameter named `id`. The framework's gin binding reads the `uri:"id"` tag; the generated client's path expansion reads the same tag — guaranteed to round-trip.
type ListArgs ¶
type ListArgs struct{}
ListArgs is empty — kept as a real type (rather than struct{}) so the generated client method has a stable shape if filters are added.
type SearchArgs ¶ added in v0.13.0
type SearchArgs struct {
Prefix string `graphql:"prefix" json:"prefix"`
}
SearchArgs is the typed input for a GraphQL query — `nexus gen clients` uses the same Params[T] pattern AsRest does.
type Service ¶
Service holds the in-memory store. Real implementations would back it with a DB; this stays simple to keep the example focused on the codegen + cross-module wiring.
func NewService ¶
type User ¶
User is the public shape returned over the wire. Generated client code lives in this package, so it sees this type without an import and consumers in other packages get it via `users.User`.
func NewGet ¶
NewGet returns a typed user by id. 404 surfaces as a *RemoteError on the client side (see the generated stub).
type UsersClient ¶
type UsersClient interface {
Get(ctx context.Context, args GetArgs) (*User, error)
List(ctx context.Context, args ListArgs) ([]*User, error)
Search(ctx context.Context, args SearchArgs) ([]*User, error)
}
UsersClient is the typed client surface for the "users" module. One method per AsRest / AsQuery / AsMutation handler in that module's declaration. The implementation is selected at construction time based on the running binary's deployment.
func NewUsersClient ¶
func NewUsersClient(app *nexus.App) UsersClient
NewUsersClient returns the appropriate implementation for the running binary:
- In-process LocalInvoker when this binary owns the "users-svc" deployment, OR when no deployment is set (monolith mode).
- HTTP RemoteCaller reading USERS_SVC_URL otherwise. The local binary's version is threaded in so RemoteCaller can detect peer-version skew on the first call (single warning line, no fail-fast).