/
entity.resolvers.go
79 lines (60 loc) · 2.26 KB
/
entity.resolvers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package graph
// This file will be automatically regenerated based on the schema, any resolver implementations
// will be copied through when generating and any unknown code will be moved to the end.
// Code generated by github.com/99designs/gqlgen version v0.17.36
import (
"context"
"fmt"
"github.com/dailytravel/x/sales/graph/model"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// FindCompanyByID is the resolver for the findCompanyByID field.
func (r *entityResolver) FindCompanyByID(ctx context.Context, id string) (*model.Company, error) {
var item *model.Company
_id, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, err
}
if err := r.db.Collection(item.Collection()).FindOne(ctx, bson.M{"_id": _id}).Decode(&item); err != nil {
return nil, err
}
return item, nil
}
// FindContactByID is the resolver for the findContactByID field.
func (r *entityResolver) FindContactByID(ctx context.Context, id string) (*model.Contact, error) {
var item *model.Contact
_id, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, err
}
if err := r.db.Collection(item.Collection()).FindOne(ctx, bson.M{"_id": _id}).Decode(&item); err != nil {
return nil, err
}
return item, nil
}
// FindMembershipByID is the resolver for the findMembershipByID field.
func (r *entityResolver) FindMembershipByID(ctx context.Context, id string) (*model.Membership, error) {
var item *model.Membership
_id, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, err
}
if err := r.db.Collection(item.Collection()).FindOne(ctx, bson.M{"_id": _id}).Decode(&item); err != nil {
return nil, err
}
return item, nil
}
// FindProductByID is the resolver for the findProductByID field.
func (r *entityResolver) FindProductByID(ctx context.Context, id string) (*model.Product, error) {
panic(fmt.Errorf("not implemented: FindProductByID - findProductByID"))
}
// FindUserByID is the resolver for the findUserByID field.
func (r *entityResolver) FindUserByID(ctx context.Context, id string) (*model.User, error) {
return &model.User{
ID: id,
}, nil
}
// Entity returns EntityResolver implementation.
func (r *Resolver) Entity() EntityResolver { return &entityResolver{r} }
type entityResolver struct{ *Resolver }