Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var MutationArticle = graphql.Fields{ "createArticle": &graphql.Field{ Type: types.TypeArticle, Description: "Create new article", Args: graphql.FieldConfigArgument{ "name": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "description": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "price": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Float), }, "images": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.NewList(types.TypeUpload)), }, "category": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "rating": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Int), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { article, err := repo.Article.Create( params.Args["name"].(string), params.Args["description"].(string), params.Args["price"].(float64), parseImages(params.Args["images"].([]interface{})), params.Args["category"].(string), int8(params.Args["rating"].(int)), ) return article, err }), }, "updateArticle": &graphql.Field{ Type: types.TypeArticle, Description: "Update product by id", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "name": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "description": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "price": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Float), }, "images": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.NewList(graphql.String)), }, "category": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "rating": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Int), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { return nil, nil return nil, nil }), }, "deleteArticle": &graphql.Field{ Type: types.TypeArticle, Description: "Delete article by id", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { aid, err := primitive.ObjectIDFromHex(params.Args["id"].(string)) err = repo.Article.DeleteArticle(aid) return nil, err }), }, }
View Source
var MutationAuth = graphql.Fields{ "getAccessToken": &graphql.Field{ Type: graphql.String, Args: graphql.FieldConfigArgument{ "signature": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, }, Description: "List catalog", Resolve: func(params graphql.ResolveParams) (interface{}, error) { secret := []byte(params.Context.Value("secret").(string)) email := os.Getenv("API_ADMIN_EMAIL") password := os.Getenv("API_ADMIN_PASSWORD") argSignarute := params.Args["signature"].(string) mac := hmac.New(sha256.New, secret) mac.Write([]byte(fmt.Sprintf("%s:%s", email, password))) phash := base64.StdEncoding.EncodeToString(mac.Sum(nil)) if argSignarute == string(phash) { token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "admin": true, "nbf": time.Now().Unix(), "exp": time.Now().Add(time.Hour * 72).Unix(), }) tokenString, err := token.SignedString(secret) return tokenString, err } return nil, fmt.Errorf("Invalid user login for %s", email) }, }, }
View Source
var MutationOrder = graphql.Fields{ "createOrder": &graphql.Field{ Type: types.TypeOrder, Description: "Create new order", Args: graphql.FieldConfigArgument{ "stockSize": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "name": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "surname": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "email": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "phone": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "address": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, "notes": &graphql.ArgumentConfig{ Type: graphql.String, }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { notes := "" if params.Args["notes"] != nil { notes = params.Args["notes"].(string) } user, err := repo.User.Create( params.Args["name"].(string), params.Args["surname"].(string), params.Args["email"].(string), params.Args["phone"].(string), params.Args["address"].(string), ) if err != nil { return nil, err } stockSize := params.Args["stockSize"].(string) stockArticle, err := repo.Article.FindStockBySize(stockSize) if err != nil { return nil, fmt.Errorf("No stock found by size %s", stockSize) } order, err := repo.Order.Create( stockArticle.ID, user.ID, notes, ) return order, err }), }, "purchaseOrder": &graphql.Field{ Type: types.TypeOrder, Description: "Purchase order", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(types.ObjectID), }, "paymentMethod": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.Int), }, "paymentRef": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { paymentMethod := int8(params.Args["paymentMethod"].(int)) order, err := repo.Order.Purchase( params.Args["id"].(primitive.ObjectID), paymentMethod, params.Args["paymentRef"].(string)) return order, err }), }, "prepareOrder": &graphql.Field{ Type: types.TypeOrder, Description: "Purchase order", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(types.ObjectID), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { order, err := repo.Order.Prepare(params.Args["id"].(primitive.ObjectID)) return order, err }), }, "shipOrder": &graphql.Field{ Type: types.TypeOrder, Description: "Purchase order", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(types.ObjectID), }, "trackingRef": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(graphql.String), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { order, err := repo.Order.Ship(params.Args["id"].(primitive.ObjectID), params.Args["trackingRef"].(string)) return order, err }), }, "confirmReceived": &graphql.Field{ Type: types.TypeOrder, Description: "Purchase order", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(types.ObjectID), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { order, err := repo.Order.ConfirmReceived(params.Args["id"].(primitive.ObjectID)) return order, err }), }, "cancelOrder": &graphql.Field{ Type: types.TypeOrder, Description: "Purchase order", Args: graphql.FieldConfigArgument{ "id": &graphql.ArgumentConfig{ Type: graphql.NewNonNull(types.ObjectID), }, }, Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) { order, err := repo.Order.Cancel(params.Args["id"].(primitive.ObjectID)) return order, err }), }, }
Mutation Create Order
View Source
var Root = util.CombineFields(MutationArticle, MutationOrder, MutationAuth)
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.