File tree 2 files changed +37
-1
lines changed
core/listeners/graphql/scalar
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -4,4 +4,7 @@ scalar TimeDefault
4
4
scalar TimeRFC3339
5
5
"""2006-01-02T15:04:05.999999999Z07:00"""
6
6
scalar TimeRFC3339Nano
7
- scalar UUID
7
+
8
+
9
+ scalar UUID
10
+ scalar NonNilUUID
Original file line number Diff line number Diff line change
1
+ package scalar
2
+
3
+ import (
4
+ "fmt"
5
+ "github.com/99designs/gqlgen/graphql"
6
+ "github.com/google/uuid"
7
+ "io"
8
+ )
9
+
10
+ func MarshalNonNilUUID (u uuid.UUID ) graphql.Marshaler {
11
+ return graphql .WriterFunc (func (w io.Writer ) {
12
+ if u == uuid .Nil {
13
+ // todo: what to do in this case?!
14
+ }
15
+ w .Write ([]byte ("\" " + u .String () + "\" " ))
16
+ })
17
+ }
18
+
19
+ func UnmarshalNonNilUUID (v interface {}) (uuid.UUID , error ) {
20
+ switch v := v .(type ) {
21
+ case string :
22
+ _uuid , _err := uuid .Parse (v )
23
+ if _err != nil {
24
+ return uuid .Nil , _err
25
+ }
26
+ if _uuid == uuid .Nil {
27
+ return uuid .Nil , fmt .Errorf ("%T nil uuid is not permitted" , v )
28
+ }
29
+ return _uuid , nil
30
+ default :
31
+ return uuid .Nil , fmt .Errorf ("%T is not a string" , v )
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments