Skip to content

Commit

Permalink
feat: add UInt64 scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed May 10, 2022
1 parent 47d66a8 commit e8d160c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
3 changes: 3 additions & 0 deletions gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ models:
- github.com/99designs/gqlgen/graphql.Int
- github.com/99designs/gqlgen/graphql.Int64
- github.com/99designs/gqlgen/graphql.Int32
UInt64:
model:
- okp4/cosmos-faucet/pkg.UInt64
Long:
model:
- github.com/99designs/gqlgen/graphql.Int64
Expand Down
38 changes: 27 additions & 11 deletions pkg/scalar.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
package pkg

import (
"errors"
"io"
"errors"
"fmt"
"io"

"github.com/99designs/gqlgen/graphql"
"github.com/99designs/gqlgen/graphql"
)

func MarshalAddress(a string) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = w.Write([]byte(a))
})
return graphql.WriterFunc(func(w io.Writer) {
_, _ = w.Write([]byte(a))
})
}

func UnmarshalAddress(v interface{}) (string, error) {
value, ok := v.(string)
if !ok {
return "", errors.New("address must be a string")
}
return value, nil
value, ok := v.(string)
if !ok {
return "", errors.New("address must be a string")
}
return value, nil
}

func MarshalUInt64(i uint64) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
_, _ = io.WriteString(w, fmt.Sprintf("%d", i))
})
}

func UnmarshalUInt64(v interface{}) (uint64, error) {
switch v := v.(type) {
case int:
return uint64(v), nil
default:
return 0, fmt.Errorf("%T is not an uint64", v)
}
}

0 comments on commit e8d160c

Please sign in to comment.