graph2: Added File type and queries.
the build failed

This commit is contained in:
2018-09-16 11:30:18 +02:00
parent 875dac9ecb
commit bac57bc378
10 changed files with 261 additions and 0 deletions
+4
View File
@@ -34,5 +34,9 @@ models:
fields:
fictionalDate:
resolver: true
File:
model: git.aiterp.net/rpdata/api/models.File
FilesFilter:
model: git.aiterp.net/rpdata/api/models/files.Filter
Date:
model: git.aiterp.net/rpdata/api/models/scalars.Date
+4
View File
@@ -29,3 +29,7 @@ func (r *rootResolver) Log() LogResolver {
func (r *rootResolver) Chapter() ChapterResolver {
return &types.ChapterResolver
}
func (r *rootResolver) File() FileResolver {
return &types.FileResolver
}
+34
View File
@@ -0,0 +1,34 @@
package queries
import (
"context"
"git.aiterp.net/rpdata/api/internal/auth"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/files"
)
func (r *resolver) File(ctx context.Context, id string) (models.File, error) {
return files.FindID(id)
}
func (r *resolver) Files(ctx context.Context, filter *files.Filter) ([]models.File, error) {
token := auth.TokenFromContext(ctx)
if filter == nil {
filter = &files.Filter{}
}
// Only allow users to view public files that are not their own.
if token != nil {
if filter.Public == nil || *filter.Public == false {
filter.Author = &token.UserID
}
} else {
filter.Public = &trueValue
}
return files.List(filter)
}
var trueValue = true
+7
View File
@@ -37,6 +37,13 @@ type Query {
# Find all distinct tags used in stories
tags: [Tag!]!
# Find file by ID
file(id: String!): File!
# Find files
files(filter: FilesFilter): [File!]!
}
# A Date represents a RFC3339 encoded date with up to millisecond precision.
+52
View File
@@ -0,0 +1,52 @@
# A File contains information about a file and where to download it.
type File {
# The file's unique ID
id: String!
# The kind of file. Most will be "upload", but some that are ported from the wiki will have other values for this.
kind: String!
# The time of uploading
time: Date!
# Whether the file is publicly listable. Someone with knowledge of the ID
# will still be able to view it, however.
public: Boolean!
# The file's name
name: String!
# The MIME type of the file
mimeType: String!
# The file's size in bytes
size: Int!
# The uploader
author: String!
# The URL where the file is hosted
url: String
}
# Filter for the files quiery.
input FilesFilter {
# If set, this will limit the results to either public or private files.
public: Boolean
# Limit the MIME types of the files.
mimeType: [String!]
}
# Input for editFile mutation
input EditFileInput {
# The file's unique ID
id: String!
# Whether the file is publicly listable. Someone with knowledge of the ID
# will still be able to view it, however.
public: Boolean
# The file's name
name: String
}
+16
View File
@@ -0,0 +1,16 @@
package types
import (
"context"
"git.aiterp.net/rpdata/api/models"
)
type fileResolver struct{}
func (r *fileResolver) Size(ctx context.Context, file *models.File) (int, error) {
return int(file.Size), nil
}
// FileResolver is a resolver
var FileResolver fileResolver