resolver_impl.go 798 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package graphql
  2. import (
  3. "context"
  4. "gshopper.com/gshopify/shop/db"
  5. "gshopper.com/gshopify/shop/graphql/generated"
  6. )
  7. type Resolver struct {
  8. db db.Database
  9. }
  10. func New(ctx context.Context, debug bool) (*Resolver, error) {
  11. r := Resolver{}
  12. var err error
  13. if r.db, err = db.New(ctx, debug); err != nil {
  14. return nil, err
  15. }
  16. return &r, nil
  17. }
  18. // Entity returns EntityResolver implementation.
  19. func (r *Resolver) Entity() generated.EntityResolver { return &entityResolver{r} }
  20. // Query returns QueryResolver implementation.
  21. func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
  22. func (r *Resolver) Close() error {
  23. var err error
  24. if r.db != nil {
  25. err = r.db.Close()
  26. }
  27. return err
  28. }
  29. type entityResolver struct{ *Resolver }
  30. type queryResolver struct{ *Resolver }