added list buckets query

This commit is contained in:
2021-09-29 21:41:50 +02:00
parent 4344bf841c
commit d2b0364445
2 changed files with 54 additions and 0 deletions

View File

@@ -100,6 +100,21 @@ func GraphqlSchema() (graphql.Schema, error) {
return auth, nil
},
},
"buckets": &graphql.Field{
Name: "buckets",
Type: graphql.NewNonNull(graphql.NewList(graphql.String)),
Description: "List available buckets",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if !helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
loader := p.Context.Value("loader").(map[string]*dataloader.Loader)
// The only reason we use a dataloader with a empty key is that we want to cache the result
thunk := loader["listBuckets"].Load(p.Context, dataloader.StringKey(""))
return thunk()
},
},
}
mutationFields := graphql.Fields{