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,
|
Size: obj.Size,
|
||||||
ContentType: obj.ContentType,
|
ContentType: obj.ContentType,
|
||||||
ETag: obj.ETag,
|
ETag: obj.ETag,
|
||||||
|
LastModified: obj.LastModified,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,6 +117,7 @@ func getFileBatch(c context.Context, k dataloader.Keys) []*dataloader.Result {
|
|||||||
Size: obj.Size,
|
Size: obj.Size,
|
||||||
ContentType: obj.ContentType,
|
ContentType: obj.ContentType,
|
||||||
ETag: obj.ETag,
|
ETag: obj.ETag,
|
||||||
|
LastModified: obj.LastModified,
|
||||||
},
|
},
|
||||||
Error: nil,
|
Error: nil,
|
||||||
})
|
})
|
||||||
|
@ -4,9 +4,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/graph-gophers/dataloader"
|
"github.com/graph-gophers/dataloader"
|
||||||
"github.com/graphql-go/graphql"
|
"github.com/graphql-go/graphql"
|
||||||
|
"github.com/graphql-go/graphql/language/ast"
|
||||||
)
|
)
|
||||||
|
|
||||||
var graphqlDirType *graphql.Object
|
var graphqlDirType *graphql.Object
|
||||||
@ -14,6 +16,38 @@ var graphqlFileType *graphql.Object
|
|||||||
|
|
||||||
// graphqlTypes create all graphql types and stores the in the global variables
|
// graphqlTypes create all graphql types and stores the in the global variables
|
||||||
func graphqlTypes() {
|
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{
|
graphqlDirType = graphql.NewObject(graphql.ObjectConfig{
|
||||||
Name: "Directory",
|
Name: "Directory",
|
||||||
Description: "Represents a directory",
|
Description: "Represents a directory",
|
||||||
@ -87,6 +121,17 @@ func graphqlTypes() {
|
|||||||
return file.ETag, nil
|
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{
|
"parent": &graphql.Field{
|
||||||
Type: graphqlDirType,
|
Type: graphqlDirType,
|
||||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||||
|
@ -27,6 +27,7 @@ type File struct {
|
|||||||
Size int64 `json:"size"`
|
Size int64 `json:"size"`
|
||||||
ContentType string `json:"contentType"`
|
ContentType string `json:"contentType"`
|
||||||
ETag string `json:"etag"`
|
ETag string `json:"etag"`
|
||||||
|
LastModified time.Time `json:"lastModified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Directory represents a directory with its metadata
|
// Directory represents a directory with its metadata
|
||||||
|
Loading…
Reference in New Issue
Block a user