-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolver_user_mutation.go
More file actions
44 lines (40 loc) · 971 Bytes
/
resolver_user_mutation.go
File metadata and controls
44 lines (40 loc) · 971 Bytes
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
package main
import (
"context"
"log"
graphql "github.com/graph-gophers/graphql-go"
)
type RegisterUserInput struct {
UserID graphql.ID
Email string
EmailVerified bool
AuthProvider string
PhotoURL *string
DisplayName *string
}
func (r *RootResolver) RegisterUser(ctx context.Context, args struct{ UserInput RegisterUserInput }) (*bool, error) {
tx, err := db.Begin()
if err != nil {
return nil, err
}
defer tx.Rollback()
_, err = tx.Exec(`
insert into users (
user_id,
email,
email_verified,
auth_provider,
photo_url,
display_name
) values ( $1, $2, $3, $4, $5, $6 )
`, args.UserInput.UserID, args.UserInput.Email, args.UserInput.EmailVerified, args.UserInput.AuthProvider, args.UserInput.PhotoURL, args.UserInput.DisplayName)
if err != nil {
return nil, err
}
err = tx.Commit()
if err != nil {
return nil, err
}
log.Printf("registered user userID=%s", args.UserInput.UserID)
return nil, nil
}