2018-11-15 12:00:08 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-14 10:50:15 +00:00
|
|
|
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"
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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,
|
2018-11-14 10:50:15 +00:00
|
|
|
Args: graphql.FieldConfigArgument{
|
2018-11-21 15:51:43 +00:00
|
|
|
input: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(types.UserInput()),
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
|
|
|
},
|
2018-11-21 15:51:43 +00:00
|
|
|
// creates user and company from input params and returns userID if succeed
|
2018-11-14 10:50:15 +00:00
|
|
|
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-14 10:50:15 +00:00
|
|
|
|
2018-11-21 15:51:43 +00:00
|
|
|
user, err := service.CreateUser(
|
2018-11-14 10:50:15 +00:00
|
|
|
p.Context,
|
2018-11-21 15:51:43 +00:00
|
|
|
userInput.User,
|
|
|
|
userInput.Company,
|
2018-11-14 10:50:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-21 15:51:43 +00:00
|
|
|
return "", err
|
2018-11-14 10:50:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 15:51:43 +00:00
|
|
|
return user.ID.String(), nil
|
2018-11-14 10:50:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|