implemented last modified
This commit is contained in:
parent
da5d597b3f
commit
31e4586d68
@ -78,6 +78,7 @@ func getFilesBatch(c context.Context, k dataloader.Keys) []*dataloader.Result {
|
||||
Size: obj.Size,
|
||||
ContentType: obj.ContentType,
|
||||
ETag: obj.ETag,
|
||||
LastModified: obj.LastModified,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -116,6 +117,7 @@ func getFileBatch(c context.Context, k dataloader.Keys) []*dataloader.Result {
|
||||
Size: obj.Size,
|
||||
ContentType: obj.ContentType,
|
||||
ETag: obj.ETag,
|
||||
LastModified: obj.LastModified,
|
||||
},
|
||||
Error: nil,
|
||||
})
|
||||
|
@ -4,9 +4,11 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/graph-gophers/dataloader"
|
||||
"github.com/graphql-go/graphql"
|
||||
"github.com/graphql-go/graphql/language/ast"
|
||||
)
|
||||
|
||||
var graphqlDirType *graphql.Object
|
||||
@ -14,6 +16,38 @@ var graphqlFileType *graphql.Object
|
||||
|
||||
// graphqlTypes create all graphql types and stores the in the global variables
|
||||
func graphqlTypes() {
|
||||
|
||||
var dateTimeType = graphql.NewScalar(graphql.ScalarConfig{
|
||||
Name: "DateTime",
|
||||
Description: "DateTime is a DateTime in ISO 8601 format",
|
||||
Serialize: func(value interface{}) interface{} {
|
||||
switch value := value.(type) {
|
||||
case time.Time:
|
||||
return value.Format(time.RFC3339)
|
||||
}
|
||||
|
||||
return "INVALID"
|
||||
},
|
||||
ParseValue: func(value interface{}) interface{} {
|
||||
switch tvalue := value.(type) {
|
||||
case string:
|
||||
if tval, err := time.Parse(time.RFC3339, tvalue); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
return tval
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
ParseLiteral: func(valueAST ast.Value) interface{} {
|
||||
switch valueAST := valueAST.(type) {
|
||||
case *ast.StringValue:
|
||||
return valueAST.Value
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
graphqlDirType = graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: "Directory",
|
||||
Description: "Represents a directory",
|
||||
@ -87,6 +121,17 @@ func graphqlTypes() {
|
||||
return file.ETag, nil
|
||||
},
|
||||
},
|
||||
"lastModified": &graphql.Field{
|
||||
Type: dateTimeType,
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
file, err := loadFile(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return file.LastModified, nil
|
||||
},
|
||||
},
|
||||
"parent": &graphql.Field{
|
||||
Type: graphqlDirType,
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
|
@ -27,6 +27,7 @@ type File struct {
|
||||
Size int64 `json:"size"`
|
||||
ContentType string `json:"contentType"`
|
||||
ETag string `json:"etag"`
|
||||
LastModified time.Time `json:"lastModified"`
|
||||
}
|
||||
|
||||
// Directory represents a directory with its metadata
|
||||
|
Loading…
Reference in New Issue
Block a user