Skip to content

Commit

Permalink
fix(gql): gql time marshaler
Browse files Browse the repository at this point in the history
Signed-off-by: Godefroy Ponsinet <godefroy.ponsinet@outlook.com>
  • Loading branch information
90dy committed Dec 11, 2018
1 parent 02b784e commit 0f0673c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions core/api/node/graphql/models/scalar.go
Expand Up @@ -72,7 +72,9 @@ func UnmarshalString(v interface{}) (string, error) {
}

func MarshalTime(t time.Time) graphql.Marshaler {
return graphql.MarshalTime(t)
return graphql.WriterFunc(func(w io.Writer) {
io.WriteString(w, strconv.Quote(t.String()))
})
}

func UnmarshalTime(v interface{}) (time.Time, error) {
Expand All @@ -84,9 +86,9 @@ func UnmarshalTime(v interface{}) (time.Time, error) {
if len(v) == 0 {
return time.Time{}, nil
}
return graphql.UnmarshalTime(v)
return time.Parse(time.RFC3339Nano, v)
default:
return graphql.UnmarshalTime(v)
return time.Time{}, errors.New("time should be RFC3339Nano formatted string")
}
return graphql.UnmarshalTime(v)
}
Expand Down
12 changes: 6 additions & 6 deletions core/api/node/graphql/resolver.go
Expand Up @@ -349,9 +349,9 @@ func (r *queryResolver) EventList(ctx context.Context, filter *p2p.Event, rawOnl
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.String()
cursor = n.CreatedAt.Format(time.RFC3339Nano)
case "updated_at":
cursor = n.UpdatedAt.String()
cursor = n.UpdatedAt.Format(time.RFC3339Nano)
}

output.Edges = append(output.Edges, &node.EventEdge{
Expand Down Expand Up @@ -432,9 +432,9 @@ func (r *queryResolver) ContactList(ctx context.Context, filter *entity.Contact,
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.String()
cursor = n.CreatedAt.Format(time.RFC3339Nano)
case "updated_at":
cursor = n.UpdatedAt.String()
cursor = n.UpdatedAt.Format(time.RFC3339Nano)
}

output.Edges = append(output.Edges, &node.ContactEdge{
Expand Down Expand Up @@ -503,9 +503,9 @@ func (r *queryResolver) ConversationList(ctx context.Context, filter *entity.Con
case "", "id":
cursor = n.ID
case "created_at":
cursor = n.CreatedAt.String()
cursor = n.CreatedAt.Format(time.RFC3339Nano)
case "updated_at":
cursor = n.UpdatedAt.String()
cursor = n.UpdatedAt.Format(time.RFC3339Nano)
}

output.Edges = append(output.Edges, &node.ConversationEdge{
Expand Down

0 comments on commit 0f0673c

Please sign in to comment.