Documentation
¶
Overview ¶
Package rocket provides developer-friendly GraphQL patterns for Go Bringing a modern, DX-focused approach to GraphQL development in Golang
Index ¶
- Constants
- func DefaultFieldResolver(p ResolveParams) (interface{}, error)
- func Handler(schema *Schema) http.HandlerFunc
- func PlaygroundHandler(endpoint string) http.HandlerFunc
- func PlaygroundHandlerWithType(endpoint string, playgroundType PlaygroundType) http.HandlerFunc
- type Config
- type Error
- type FieldResolveFn
- type ModuleResolvers
- type PlaygroundType
- type Request
- type ResolveInfo
- type ResolveParams
- type ResolverRegistry
- type Result
- type RocketDataSource
- type RocketDataSourceFactory
- func (f *RocketDataSourceFactory) Context() context.Context
- func (f *RocketDataSourceFactory) Planner(_ abstractlogger.Logger) plan.DataSourcePlanner[interface{}]
- func (f *RocketDataSourceFactory) PlanningBehavior() plan.DataSourcePlanningBehavior
- func (f *RocketDataSourceFactory) ToDataSourceConfiguration(id, name string) (plan.DataSourceConfiguration[interface{}], error)
- func (f *RocketDataSourceFactory) UpstreamSchema(config plan.DataSourceConfiguration[interface{}]) (*ast.Document, bool)
- type RocketPlanner
- func (p *RocketPlanner) ConfigureFetch() resolve.FetchConfiguration
- func (p *RocketPlanner) ConfigureSubscription() plan.SubscriptionConfiguration
- func (p *RocketPlanner) DataSourcePlanningBehavior() plan.DataSourcePlanningBehavior
- func (p *RocketPlanner) DownstreamResponseFieldAlias(downstreamFieldRef int) (alias string, exists bool)
- func (p *RocketPlanner) ID() int
- func (p *RocketPlanner) ObjectFetchConfiguration() *objectFetchConfiguration
- func (p *RocketPlanner) Register(visitor *plan.Visitor, configuration plan.DataSourceConfiguration[interface{}], ...) error
- func (p *RocketPlanner) SetID(id int)
- type RocketSource
- type Schema
- type SchemaCompiler
Constants ¶
const (
DefaultPreserveOrder = true
)
Config defaults
Variables ¶
This section is empty.
Functions ¶
func DefaultFieldResolver ¶
func DefaultFieldResolver(p ResolveParams) (interface{}, error)
DefaultFieldResolver automatically resolves struct fields to GraphQL fields It uses reflection to map GraphQL field names to Go struct fields This provides a developer-friendly auto-resolution feature
func Handler ¶
func Handler(schema *Schema) http.HandlerFunc
Handler creates an HTTP handler for GraphQL requests Works with both net/http and Gin (via gin.WrapH)
func PlaygroundHandler ¶
func PlaygroundHandler(endpoint string) http.HandlerFunc
PlaygroundHandler creates an HTTP handler that serves a GraphQL playground Uses Apollo Sandbox by default (most modern and stable)
func PlaygroundHandlerWithType ¶
func PlaygroundHandlerWithType(endpoint string, playgroundType PlaygroundType) http.HandlerFunc
PlaygroundHandlerWithType creates a playground handler with a specific type
Types ¶
type Config ¶
type Config struct {
SchemaPath string // Path to the compiled schema.graphql file
EnablePlayground bool // Enable GraphQL playground (default: false)
}
Config holds configuration for building a GraphQL schema
type Error ¶
type Error struct {
Message string `json:"message"`
Path []interface{} `json:"path,omitempty"`
}
Error represents a GraphQL error
type FieldResolveFn ¶
type FieldResolveFn func(p ResolveParams) (interface{}, error)
FieldResolveFn is a function that resolves a field value
type ModuleResolvers ¶
type ModuleResolvers interface {
QueryResolvers() map[string]FieldResolveFn
MutationResolvers() map[string]FieldResolveFn
TypeResolvers() map[string]map[string]FieldResolveFn
}
ModuleResolvers is the interface that all module resolvers must implement This provides a clean, modular approach to organizing resolvers
type PlaygroundType ¶
type PlaygroundType string
PlaygroundType determines which playground interface to use
const ( PlaygroundTypeApolloSandbox PlaygroundType = "apollo" // Apollo Sandbox (recommended) PlaygroundTypeGraphiQL PlaygroundType = "graphiql" // GraphiQL (stable) PlaygroundTypePlayground PlaygroundType = "playground" // GraphQL Playground (legacy) )
type Request ¶
type Request struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables"`
OperationName string `json:"operationName"`
}
Request represents a GraphQL HTTP request
type ResolveInfo ¶
type ResolveInfo struct {
FieldName string
Path []string
ParentType string
ReturnType string
SelectionSet interface{} // Will be wundergraph AST selection set
}
ResolveInfo contains metadata about the field being resolved
type ResolveParams ¶
type ResolveParams struct {
Source interface{}
Args map[string]interface{}
Context context.Context
Info ResolveInfo
}
ResolveParams contains all the information for resolving a field
type ResolverRegistry ¶
type ResolverRegistry struct {
Query map[string]FieldResolveFn
Mutation map[string]FieldResolveFn
Types map[string]map[string]FieldResolveFn
}
ResolverRegistry holds all resolvers stitched together Combines resolvers from different modules in a clean, modular way
func NewResolverRegistry ¶
func NewResolverRegistry(modules ...ModuleResolvers) *ResolverRegistry
NewResolverRegistry creates a new registry by merging module resolvers This is like:
export const resolvers = {
Query: { ...userQueries, ...orgQueries },
Mutation: { ...userMutations, ...orgMutations }
}
func (*ResolverRegistry) GetMutationResolver ¶
func (r *ResolverRegistry) GetMutationResolver(name string) (FieldResolveFn, bool)
GetMutationResolver returns a mutation resolver by name
func (*ResolverRegistry) GetQueryResolver ¶
func (r *ResolverRegistry) GetQueryResolver(name string) (FieldResolveFn, bool)
GetQueryResolver returns a query resolver by name
func (*ResolverRegistry) GetTypeResolver ¶
func (r *ResolverRegistry) GetTypeResolver(typeName, fieldName string) (FieldResolveFn, bool)
GetTypeResolver returns a type's field resolver
type Result ¶
type Result struct {
Data interface{} `json:"data,omitempty"`
Errors []Error `json:"errors,omitempty"`
}
Result represents the result of a GraphQL operation
func ExecutePlan ¶ added in v0.2.0
func ExecutePlan(ctx context.Context, execPlan plan.Plan, variables map[string]interface{}, resolvers *ResolverRegistry) *Result
ExecutePlan executes a GraphQL execution plan using graphql-go-tools resolver
type RocketDataSource ¶ added in v0.2.0
type RocketDataSource struct {
// contains filtered or unexported fields
}
RocketDataSource bridges Rocket's resolver pattern to graphql-go-tools DataSource This allows Rocket to work with graphql-go-tools while maintaining its developer-friendly API
type RocketDataSourceFactory ¶ added in v0.2.0
type RocketDataSourceFactory struct {
// contains filtered or unexported fields
}
RocketDataSourceFactory creates RocketDataSource instances
func NewRocketDataSourceFactory ¶ added in v0.2.0
func NewRocketDataSourceFactory(resolvers *ResolverRegistry, schema *ast.Document) *RocketDataSourceFactory
NewRocketDataSourceFactory creates a new factory for Rocket DataSources
func (*RocketDataSourceFactory) Context ¶ added in v0.2.0
func (f *RocketDataSourceFactory) Context() context.Context
func (*RocketDataSourceFactory) Planner ¶ added in v0.2.0
func (f *RocketDataSourceFactory) Planner(_ abstractlogger.Logger) plan.DataSourcePlanner[interface{}]
func (*RocketDataSourceFactory) PlanningBehavior ¶ added in v0.2.0
func (f *RocketDataSourceFactory) PlanningBehavior() plan.DataSourcePlanningBehavior
func (*RocketDataSourceFactory) ToDataSourceConfiguration ¶ added in v0.2.0
func (f *RocketDataSourceFactory) ToDataSourceConfiguration(id, name string) (plan.DataSourceConfiguration[interface{}], error)
ToDataSourceConfiguration converts the factory to a DataSourceConfiguration This allows it to be used in plan.Configuration.DataSources
func (*RocketDataSourceFactory) UpstreamSchema ¶ added in v0.2.0
func (f *RocketDataSourceFactory) UpstreamSchema(config plan.DataSourceConfiguration[interface{}]) (*ast.Document, bool)
type RocketPlanner ¶ added in v0.2.0
type RocketPlanner struct {
// contains filtered or unexported fields
}
RocketPlanner implements plan.DataSourcePlanner for Rocket resolvers It configures how fields are resolved using Rocket's resolver pattern
func (*RocketPlanner) ConfigureFetch ¶ added in v0.2.0
func (p *RocketPlanner) ConfigureFetch() resolve.FetchConfiguration
func (*RocketPlanner) ConfigureSubscription ¶ added in v0.2.0
func (p *RocketPlanner) ConfigureSubscription() plan.SubscriptionConfiguration
func (*RocketPlanner) DataSourcePlanningBehavior ¶ added in v0.2.0
func (p *RocketPlanner) DataSourcePlanningBehavior() plan.DataSourcePlanningBehavior
func (*RocketPlanner) DownstreamResponseFieldAlias ¶ added in v0.2.0
func (p *RocketPlanner) DownstreamResponseFieldAlias(downstreamFieldRef int) (alias string, exists bool)
func (*RocketPlanner) ID ¶ added in v0.2.0
func (p *RocketPlanner) ID() int
func (*RocketPlanner) ObjectFetchConfiguration ¶ added in v0.2.0
func (p *RocketPlanner) ObjectFetchConfiguration() *objectFetchConfiguration
ObjectFetchConfiguration is called during planning to get field-specific configuration This method returns a pointer to the same object, so graphql-go-tools can populate rootFields
func (*RocketPlanner) Register ¶ added in v0.2.0
func (p *RocketPlanner) Register(visitor *plan.Visitor, configuration plan.DataSourceConfiguration[interface{}], _ plan.DataSourcePlannerConfiguration) error
func (*RocketPlanner) SetID ¶ added in v0.2.0
func (p *RocketPlanner) SetID(id int)
type RocketSource ¶ added in v0.2.0
type RocketSource struct {
// contains filtered or unexported fields
}
RocketSource implements resolve.DataSource for Rocket resolvers This is where we actually execute Rocket's resolver functions
func (*RocketSource) LoadWithFiles ¶ added in v0.2.0
func (s *RocketSource) LoadWithFiles(ctx context.Context, input []byte, files []*httpclient.FileUpload, out *bytes.Buffer) error
type Schema ¶
type Schema struct {
// contains filtered or unexported fields
}
Schema represents a compiled and executable GraphQL schema
func BuildSchema ¶
func BuildSchema(config Config, modules ...ModuleResolvers) (*Schema, error)
BuildSchema builds an executable GraphQL schema from .graphql file and module resolvers This is the main entry point for Rocket
type SchemaCompiler ¶
type SchemaCompiler struct {
// contains filtered or unexported fields
}
SchemaCompiler compiles multiple .graphql files into a single schema
func NewSchemaCompiler ¶
func NewSchemaCompiler(sourceDir, outputFile string) *SchemaCompiler
NewSchemaCompiler creates a new schema compiler
func (*SchemaCompiler) Compile ¶
func (c *SchemaCompiler) Compile() error
Compile finds all .graphql files and concatenates them into a single schema
func (*SchemaCompiler) CompileIfNeeded ¶
func (c *SchemaCompiler) CompileIfNeeded() (bool, error)
CompileIfNeeded compiles the schema only if source files are newer than output