/
user.go
38 lines (34 loc) 路 831 Bytes
/
user.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
package schemas
import (
"github.com/graphql-go/graphql"
"github.com/hongbo-miao/hongbomiao.com/api-go/internal/graphql_server/utils"
"github.com/rs/zerolog/log"
)
var userGraphQLType = graphql.NewObject(graphql.ObjectConfig{
Name: "User",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.ID,
},
"name": &graphql.Field{
Type: graphql.String,
},
},
})
var userGraphQLField = graphql.Field{
Type: userGraphQLType,
Args: graphql.FieldConfigArgument{
"id": &graphql.ArgumentConfig{
Type: graphql.NewNonNull(graphql.ID),
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
err := utils.CheckGraphQLContextMyID(p)
if err != nil {
log.Error().Err(err).Msg("CheckGraphQLContextMyID")
return nil, err
}
id := p.Args["id"].(string)
return utils.GetUser(id)
},
}