resolver_impl.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package graphql
  2. import (
  3. "context"
  4. "gshopper.com/gshopify/products/db"
  5. "gshopper.com/gshopify/products/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. // Query returns QueryResolver implementation.
  19. func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} }
  20. // Product returns ProductResolver implementation.
  21. func (r *Resolver) Product() generated.ProductResolver { return &productResolver{r} }
  22. // ProductVariant returns ProductVariantResolver implementation.
  23. func (r *Resolver) ProductVariant() generated.ProductVariantResolver {
  24. return &productVariantResolver{r}
  25. }
  26. // Collection returns CollectionResolver implementation.
  27. func (r *Resolver) Collection() generated.CollectionResolver { return &collectionResolver{r} }
  28. func (r *Resolver) Close() error {
  29. var err error
  30. if r.db != nil {
  31. err = r.db.Close()
  32. }
  33. return err
  34. }
  35. type queryResolver struct{ *Resolver }
  36. type productResolver struct{ *Resolver }
  37. type productVariantResolver struct{ *Resolver }
  38. type collectionResolver struct{ *Resolver }