Browse Source

Replaced custom Date scalar code with gqlgen's built-in Time scalar.

thegreatrefactor
Gisle Aune 6 years ago
parent
commit
7b253748fe
  1. 13
      graph2/gqlgen.yml
  2. 4
      graph2/schema/root.gql
  3. 4
      graph2/schema/types/Change.gql
  4. 10
      graph2/schema/types/Chapter.gql
  5. 10
      graph2/schema/types/Comment.gql
  6. 2
      graph2/schema/types/File.gql
  7. 6
      graph2/schema/types/Log.gql
  8. 6
      graph2/schema/types/Post.gql
  9. 14
      graph2/schema/types/Story.gql
  10. 28
      models/scalars/date.go

13
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
model: git.aiterp.net/rpdata/api/models.User

4
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

4
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

10
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

10
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

2
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.

6
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!

6
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

14
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

28
models/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)
}
}
Loading…
Cancel
Save