From 7b253748fe14cafe476df993b5ae69c5135f245d Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 9 Jun 2019 12:49:18 +0200 Subject: [PATCH] Replaced custom Date scalar code with gqlgen's built-in Time scalar. --- graph2/gqlgen.yml | 13 +------------ graph2/schema/root.gql | 4 ++-- graph2/schema/types/Change.gql | 4 ++-- graph2/schema/types/Chapter.gql | 10 +++++----- graph2/schema/types/Comment.gql | 10 +++++----- graph2/schema/types/File.gql | 2 +- graph2/schema/types/Log.gql | 6 +++--- graph2/schema/types/Post.gql | 6 +++--- graph2/schema/types/Story.gql | 14 +++++++------- models/scalars/date.go | 28 ---------------------------- 10 files changed, 29 insertions(+), 68 deletions(-) delete mode 100644 models/scalars/date.go diff --git a/graph2/gqlgen.yml b/graph2/gqlgen.yml index f01d360..526145a 100644 --- a/graph2/gqlgen.yml +++ b/graph2/gqlgen.yml @@ -39,21 +39,12 @@ models: model: git.aiterp.net/rpdata/api/models.LogImporter Comment: model: git.aiterp.net/rpdata/api/models.Comment - fields: - fictionalDate: - resolver: true ChapterCommentMode: model: git.aiterp.net/rpdata/api/models.ChapterCommentMode Chapter: model: git.aiterp.net/rpdata/api/models.Chapter - fields: - fictionalDate: - resolver: true Story: model: git.aiterp.net/rpdata/api/models.Story - fields: - fictionalDate: - resolver: true StoryCategory: model: git.aiterp.net/rpdata/api/models.StoryCategory StoriesFilter: @@ -75,6 +66,4 @@ models: Token: model: git.aiterp.net/rpdata/api/models.Token User: - model: git.aiterp.net/rpdata/api/models.User - Date: - model: git.aiterp.net/rpdata/api/models/scalars.Date \ No newline at end of file + model: git.aiterp.net/rpdata/api/models.User \ No newline at end of file diff --git a/graph2/schema/root.gql b/graph2/schema/root.gql index cad292c..bb00b30 100644 --- a/graph2/schema/root.gql +++ b/graph2/schema/root.gql @@ -167,6 +167,6 @@ type Subscription { changes(keys: [ChangeKeyInput!]!): Change! } -# A Date represents a RFC3339 encoded date with up to millisecond precision. -scalar Date +# A Time represents a RFC3339 encoded date with up to millisecond precision. +scalar Time diff --git a/graph2/schema/types/Change.gql b/graph2/schema/types/Change.gql index c45fad5..28326d7 100644 --- a/graph2/schema/types/Change.gql +++ b/graph2/schema/types/Change.gql @@ -21,7 +21,7 @@ type Change { keys: [ChangeKey!]! "The date when the change happened." - date: Date + date: Time "The changed objects." objects: [ChangeObject!]! @@ -74,7 +74,7 @@ input ChangesFilter { keys: [ChangeKeyInput!] "Only show changes more recent than this date." - earliestDate: Date + earliestDate: Time "Limit the amount of results." limit: Int diff --git a/graph2/schema/types/Chapter.gql b/graph2/schema/types/Chapter.gql index d82f371..1c6d8da 100644 --- a/graph2/schema/types/Chapter.gql +++ b/graph2/schema/types/Chapter.gql @@ -13,13 +13,13 @@ type Chapter { source: String! # When the chapter was posted initialy - createdDate: Date! + createdDate: Time! # The in-universe date and time of the chapter - fictionalDate: Date + fictionalDate: Time # The date of edit. - editedDate: Date! + editedDate: Time! "The comment mode." commentMode: ChapterCommentMode! @@ -69,7 +69,7 @@ input ChapterAddInput { source: String! # Optionally, assign a fictional date for the chapter - fictionalDate: Date + fictionalDate: Time "The comment mode for the chapter." commentMode: ChapterCommentMode @@ -87,7 +87,7 @@ input ChapterEditInput { source: String # Set the fictional date for a chapter - fictionalDate: Date + fictionalDate: Time # Remove the fictional date for a chapter clearFictionalDate: Boolean diff --git a/graph2/schema/types/Comment.gql b/graph2/schema/types/Comment.gql index e322d18..4ceeb01 100644 --- a/graph2/schema/types/Comment.gql +++ b/graph2/schema/types/Comment.gql @@ -21,13 +21,13 @@ type Comment { character: Character "The fictional (IC) date of the comment." - fictionalDate: Date + fictionalDate: Time "The date of creation." - createdDate: Date! + createdDate: Time! "The date of the last edit." - editedDate: Date! + editedDate: Time! "The markdown source of the comment." source: String! @@ -50,7 +50,7 @@ input CommentAddInput { characterId: String "Optional in-universe date of the comment." - fictionalDate: Date + fictionalDate: Time "Optional subject to add to the comment, only shown in some modes." subject: String @@ -73,7 +73,7 @@ input CommentEditInput { characterId: String "Change the optional in-universe date of the comment." - fictionalDate: Date + fictionalDate: Time "Set to clear the fictional date." clearFictionalDate: Boolean diff --git a/graph2/schema/types/File.gql b/graph2/schema/types/File.gql index 0eafcc3..9180a3d 100644 --- a/graph2/schema/types/File.gql +++ b/graph2/schema/types/File.gql @@ -7,7 +7,7 @@ type File { kind: String! # The time of uploading - time: Date! + time: Time! # Whether the file is publicly listable. Someone with knowledge of the ID # will still be able to view it, however. diff --git a/graph2/schema/types/Log.gql b/graph2/schema/types/Log.gql index 7c1ad57..0d5a89d 100644 --- a/graph2/schema/types/Log.gql +++ b/graph2/schema/types/Log.gql @@ -8,7 +8,7 @@ type Log { shortId: String! # The date for a log. - date: Date! + date: Time! # The channel of a log. channelName: String! @@ -60,7 +60,7 @@ input LogsFilter { # Input for addLog mutation input LogAddInput { # The date of the log. - date: Date! + date: Time! # The channel where the log is set channel: String! @@ -116,7 +116,7 @@ input LogImportInput { timezone: String "The date of the log, if not provided in the log body." - date: Date + date: Time "The log body itself." data: String! diff --git a/graph2/schema/types/Post.gql b/graph2/schema/types/Post.gql index 166f24c..1268fc2 100644 --- a/graph2/schema/types/Post.gql +++ b/graph2/schema/types/Post.gql @@ -7,7 +7,7 @@ type Post { logId: String! # The date and time of posting - time: Date! + time: Time! # The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. kind: String! @@ -28,7 +28,7 @@ input PostAddInput { logId: String! # The date and time of posting, in a RFC3339 format with up to a nanosecond's precision - time: Date! + time: Time! # The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. kind: String! @@ -46,7 +46,7 @@ input PostEditInput { id: String! # The date and time of posting, in a RFC3339 format with up to a nanosecond's precision - time: Date + time: Time # The kind of post this is. Only "text", "scene" and "action" are RP, while others are annotations and 'commands'. kind: String diff --git a/graph2/schema/types/Story.gql b/graph2/schema/types/Story.gql index 57ba0ef..cf81921 100644 --- a/graph2/schema/types/Story.gql +++ b/graph2/schema/types/Story.gql @@ -26,13 +26,13 @@ type Story { chapters: [Chapter!]! # The date the story was created. - createdDate: Date! + createdDate: Time! # The date the story is set in. - fictionalDate: Date + fictionalDate: Time # The date of the last major update to the story. This being bumped means a new chapter has been added. - updatedDate: Date! + updatedDate: Time! } # Filter for stories query. @@ -53,10 +53,10 @@ input StoriesFilter { open: Boolean # The earliest fictionalDate - earliestFictionalDate: Date + earliestFictionalDate: Time # The latest fictionalDate - latestFictionalDate: Date + latestFictionalDate: Time # The max amount of stories to get (default: 30) limit: Int @@ -85,7 +85,7 @@ input StoryAddInput { tags: [TagInput!] # Set the fictional date of the story. - fictionalDate: Date + fictionalDate: Time } # Input for the editStory mutation @@ -111,7 +111,7 @@ input StoryEditInput { listed: Boolean # Set the fictional date of the story. - fictionalDate: Date + fictionalDate: Time # Clear the fictional date of the story. clearFictionalDate: Boolean diff --git a/models/scalars/date.go b/models/scalars/date.go deleted file mode 100644 index 081872d..0000000 --- a/models/scalars/date.go +++ /dev/null @@ -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) - } -}