Replaced custom Date scalar code with gqlgen's built-in Time scalar.
the build was successful

This commit is contained in:
2019-06-09 12:49:18 +02:00
parent 53c3d4597b
commit 7b253748fe
10 changed files with 29 additions and 68 deletions
-28
View File
@@ -1,28 +0,0 @@
package scalars
import (
"fmt"
"io"
"time"
"github.com/99designs/gqlgen/graphql"
)
// MarshalDate marshals time into gql Date type
func MarshalDate(t time.Time) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
w.Write([]byte(`"` + t.Format(time.RFC3339Nano) + `"`))
})
}
// UnmarshalDate unmarshals time from gql Date type
func UnmarshalDate(v interface{}) (time.Time, error) {
switch v := v.(type) {
case string:
return time.Parse(time.RFC3339Nano, v)
case int:
return time.Unix(0, int64(v)*1000000), nil
default:
return time.Time{}, fmt.Errorf("%T is not a valid time", v)
}
}