Gisle Aune
6 years ago
10 changed files with 29 additions and 68 deletions
-
11graph2/gqlgen.yml
-
4graph2/schema/root.gql
-
4graph2/schema/types/Change.gql
-
10graph2/schema/types/Chapter.gql
-
10graph2/schema/types/Comment.gql
-
2graph2/schema/types/File.gql
-
6graph2/schema/types/Log.gql
-
6graph2/schema/types/Post.gql
-
14graph2/schema/types/Story.gql
-
28models/scalars/date.go
@ -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) |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue