storj/pkg/satellite/satelliteweb/satelliteql/mutation.go

53 lines
1.2 KiB
Go
Raw Normal View History

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package satelliteql
import (
"github.com/graphql-go/graphql"
"storj.io/storj/pkg/satellite"
)
const (
// Mutation is graphql request that modifies data
Mutation = "mutation"
2018-11-21 15:51:43 +00:00
createUserMutation = "createUser"
input = "input"
)
// rootMutation creates mutation for graphql populated by AccountsClient
func rootMutation(service *satellite.Service, types Types) *graphql.Object {
return graphql.NewObject(graphql.ObjectConfig{
Name: Mutation,
Fields: graphql.Fields{
2018-11-21 15:51:43 +00:00
createUserMutation: &graphql.Field{
Type: graphql.String,
Args: graphql.FieldConfigArgument{
2018-11-21 15:51:43 +00:00
input: &graphql.ArgumentConfig{
Type: graphql.NewNonNull(types.UserInput()),
},
},
2018-11-21 15:51:43 +00:00
// creates user and company from input params and returns userID if succeed
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
2018-11-21 15:51:43 +00:00
var userInput = fromMapUserInfo(p.Args[input].(map[string]interface{}))
2018-11-21 15:51:43 +00:00
user, err := service.CreateUser(
p.Context,
2018-11-21 15:51:43 +00:00
userInput.User,
userInput.Company,
)
if err != nil {
2018-11-21 15:51:43 +00:00
return "", err
}
2018-11-21 15:51:43 +00:00
return user.ID.String(), nil
},
},
},
})
}