Skip to content

Commit

Permalink
feat(directive): add func resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Feb 1, 2024
1 parent 9bdf0dd commit 8be965f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions directive/func-resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package directive

import "context"

// FuncResolver resolves a directive with a function.
type FuncResolver struct {
fn func(ctx context.Context, handler ResolverHandler) error
}

// NewFuncResolver constructs a new FuncResolver.
func NewFuncResolver(fn func(ctx context.Context, handler ResolverHandler) error) *FuncResolver {
return &FuncResolver{fn: fn}
}

// Resolve resolves the values, emitting them to the handler.
func (r *FuncResolver) Resolve(ctx context.Context, handler ResolverHandler) error {
if r.fn == nil {
return nil
}
return r.fn(ctx, handler)
}

// _ is a type assertion
var _ Resolver = ((*FuncResolver)(nil))

0 comments on commit 8be965f

Please sign in to comment.