Gisle Aune
6 years ago
6 changed files with 127 additions and 2 deletions
-
2Gopkg.lock
-
4graph2/gqlgen.yml
-
15graph2/queries/post.go
-
10graph2/schema/root.gql
-
68graph2/schema/types/Post.gql
-
28model/scalars/date.go
@ -0,0 +1,15 @@ |
|||
package queries |
|||
|
|||
import ( |
|||
"context" |
|||
|
|||
"git.aiterp.net/rpdata/api/model/log" |
|||
) |
|||
|
|||
func (r *resolver) Post(ctx context.Context, id string) (log.Post, error) { |
|||
return log.FindPostID(id) |
|||
} |
|||
|
|||
func (r *resolver) Posts(ctx context.Context, ids []string) ([]log.Post, error) { |
|||
return log.ListPostIDs(ids...) |
|||
} |
@ -0,0 +1,68 @@ |
|||
# A Post is a part of a log |
|||
type Post { |
|||
# The post's ID |
|||
id: String! |
|||
|
|||
# The post's Log ID. This is the closest thing to a link back since this API graph doesn't have any cycles. |
|||
logId: String! |
|||
|
|||
# The date and time of posting |
|||
time: Date! |
|||
|
|||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. |
|||
kind: String! |
|||
|
|||
# The character nick |
|||
nick: String! |
|||
|
|||
# The post's text, which purpose depends on the kind |
|||
text: String! |
|||
|
|||
# The post's position, used for reordering |
|||
position: Int! |
|||
} |
|||
|
|||
# Input for the addPost mutation |
|||
input AddPostInput { |
|||
# The log's ID that this post should be a part of |
|||
logId: String! |
|||
|
|||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision |
|||
time: Date! |
|||
|
|||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. |
|||
kind: String! |
|||
|
|||
# The character nick, or command invoker for non-RP stuff |
|||
nick: String! |
|||
|
|||
# The post's text, which purpose depends on the kind |
|||
text: String! |
|||
} |
|||
|
|||
# Input for the editPost mutation |
|||
input EditPostInput { |
|||
# The Post ID |
|||
id: String! |
|||
|
|||
# The date and time of posting, in a RFC3339 format with up to a nanosecond's precision |
|||
time: Date |
|||
|
|||
# The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. |
|||
kind: String |
|||
|
|||
# The character nick, or command invoker for non-RP stuff |
|||
nick: String |
|||
|
|||
# The post's text, which purpose depends on the kind |
|||
text: String |
|||
} |
|||
|
|||
# Input for the movePost mutation |
|||
input MovePostInput { |
|||
# The Post ID |
|||
id: String! |
|||
|
|||
# Target index |
|||
toPosition: Int! |
|||
} |
@ -0,0 +1,28 @@ |
|||
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