types

package
v0.0.0-...-cae665e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cursor = graphql.NewScalar(graphql.ScalarConfig{
	Name:        "Cursor",
	Description: "",
	Serialize: func(value interface{}) interface{} {
		if oid, ok := value.(primitive.ObjectID); ok {
			return oid
		}
		return nil
	},
	ParseValue: func(value interface{}) interface{} {
		if v, ok := value.(primitive.ObjectID); ok {
			return v.Hex()
		}
		return fmt.Sprintf("%v", value)
	},
	ParseLiteral: func(valueAST ast.Value) interface{} {
		switch valueAST := valueAST.(type) {
		case *ast.StringValue:
			return valueAST.Value
		}
		return nil
	},
})
View Source
var FieldArticle = graphql.Field{
	Type:        TypeArticle,
	Description: "Article",
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		if id, ok := utils.GetValueByJSONTag(params.Source, "article"); ok {
			article, err := model.Article.FindOne(utils.NewIdArgs(id))
			return article, err

		}
		return nil, nil
	}),
}

FieldArticle GraphQL field

View Source
var FieldArticlePriceRange = &graphql.Field{
	Type:        graphql.NewList(graphql.Float),
	Description: "Get min max price",
	Args: graphql.FieldConfigArgument{
		"sizes": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
		"categories": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
	},
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) {
		rangePrice, err := repo.Article.GetPriceRange(&params.Args)
		return []float64{rangePrice.Min, rangePrice.Max}, err
	}),
}
View Source
var FieldArticleStock = &graphql.Field{
	Type: graphql.NewList(TypeArticleStockOrder),
	Args: graphql.FieldConfigArgument{
		"id": &graphql.ArgumentConfig{
			Type: ObjectID,
		},
	},
	Description: "Get article stock list",
	Resolve: decs.ContextAuthIsAdmin(decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) {

		return nil, nil

	})),
}
View Source
var FieldCursor = &graphql.Field{
	Type:        graphql.ID,
	Description: "Cursor for use in pagination",
}

Cursor GraphQL field definition used in pagination in order to establish a point reference

View Source
var FieldGetArticle = &graphql.Field{
	Type:        TypeArticle,
	Description: "Get article by id",
	Args: graphql.FieldConfigArgument{
		"id": &graphql.ArgumentConfig{
			Type: graphql.NewNonNull(ObjectID),
		},
	},
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		article, err := model.Article.FindOne(&params.Args)
		return article, err
	}),
}
View Source
var FieldGetOrder = &graphql.Field{
	Type:        TypeOrder,
	Description: "Get order by id",
	Args: graphql.FieldConfigArgument{
		"id": &graphql.ArgumentConfig{
			Type: ObjectID,
		},
	},
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		order, err := model.Order.FindOne(&params.Args)
		return order, err
	}),
}
View Source
var FieldID = graphql.Field{
	Type: ObjectID,
}

ID GraphQL field definition used to identify a resource

View Source
var FieldListArticleCategories = &graphql.Field{
	Description: "List article categories using filters",
	Type:        TypeDistinctList,
	Args: graphql.FieldConfigArgument{
		"sizes": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
		"priceRange": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.Float),
		},
	},
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) {
		categories, err := repo.Article.GetCategories(&params.Args)
		return categories, err
	}),
}
View Source
var FieldListArticleSizes = &graphql.Field{
	Description: "List the article sizes using filters",
	Type:        TypeDistinctList,
	Args: graphql.FieldConfigArgument{
		"categories": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
		"priceRange": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.Float),
		},
	},
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, repo mongodb.Repo) (interface{}, error) {
		sizes, err := repo.Article.GetSizes(&params.Args)
		return sizes, err
	}),
}
View Source
var FieldListArticles = &graphql.Field{
	Type:        TypeArticleConnection,
	Description: "Get articles list",
	Args: relay.NewConnectionArgs(graphql.FieldConfigArgument{
		"categories": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
		"priceRange": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.Float),
		},
		"sizes": &graphql.ArgumentConfig{
			Type: graphql.NewList(graphql.String),
		},
		"sorting": &graphql.ArgumentConfig{
			Type: graphql.NewEnum(graphql.EnumConfig{
				Name: "ArticleSortingEnum",
				Values: graphql.EnumValueConfigMap{
					"POPULAR": &graphql.EnumValueConfig{
						Value: 1,
					},
					"PURCHASES": &graphql.EnumValueConfig{
						Value: 2,
					},
					"RECENTS": &graphql.EnumValueConfig{
						Value: 3,
					},
				},
			}),
		},
	}),
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		connArgs := relay.NewConnectionArguments(params.Args)
		articles, meta, err := model.Article.FindSlice(&params.Args)
		return utils.ConnectionFromArraySlice(articles, connArgs, meta), err
	}),
}

FieldListArticles

{
  listArticles(last:3){
    pageInfo {
      endCursor
      hasNextPage
      hasPreviousPage
      startCursor
    }
    edges {
      cursor
      node {
        category
        description
        id
        images
        name
        price
        rating
      }
    }
  }
}
View Source
var FieldListArticlesRelated = &graphql.Field{
	Type:        TypeArticleConnection,
	Description: "Get articles list",
	Args:        relay.ConnectionArgs,
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		connArgs := relay.NewConnectionArguments(params.Args)
		articles, meta, err := model.Article.FindSlice(&params.Args)
		return utils.ConnectionFromArraySlice(articles, connArgs, meta), err
	}),
}

FieldListArticlesRelated ideally it would nice if the method does accept multiple criterias in order to reference by article or user. But at first instance it will provide only one way to obtain a list of articles related to another article using its ID and filtering by category

View Source
var FieldListCatalog = &graphql.Field{
	Type:        TypeArticleConnection,
	Description: "Get catalog list by filters",
	Args:        relay.ConnectionArgs,
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		connArgs := relay.NewConnectionArguments(params.Args)
		articles, meta, err := model.Article.FindSlice(&params.Args)
		return utils.ConnectionFromArraySlice(articles, connArgs, meta), err
	}),
}
View Source
var FieldListOrders = &graphql.Field{
	Type:        TypeOrderConnection,
	Description: "Get orders list",
	Args:        relay.ConnectionArgs,
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		connArgs := relay.NewConnectionArguments(params.Args)
		orders, meta, err := model.Order.FindSlice(&params.Args)
		return utils.ConnectionFromArraySlice(orders, connArgs, meta), err
	}),
}
View Source
var FieldStock = graphql.Field{
	Type:        TypeStock,
	Description: "Stock",
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		if id, ok := utils.GetValueByJSONTag(params.Source, "stock"); ok {
			stock, err := model.Article.FindStockById(id.(primitive.ObjectID))
			return stock, err

		}
		return nil, nil
	}),
}

FieldArticle GraphQL field

View Source
var FieldUser = graphql.Field{
	Type:        TypeUser,
	Description: "User",
	Resolve: decs.ContextRepoConsumer(func(params graphql.ResolveParams, model mongodb.Repo) (interface{}, error) {
		if id, ok := utils.GetValueByJSONTag(params.Source, "user"); ok {
			user, err := model.User.FindOne(utils.NewIdArgs(id))
			return user, err

		}
		return nil, nil
	}),
}

FieldUser GraphQL field

View Source
var ObjectID = graphql.NewScalar(graphql.ScalarConfig{
	Name: "ObjectID",
	Description: "The `ID` scalar type represents a unique identifier, often used to " +
		"refetch an object or as key for a cache. The ID type appears in a JSON " +
		"response as a String; however, it is not intended to be human-readable. " +
		"a 4-byte value representing the seconds since the Unix epoch" +
		"a 5-byte random value, and" +
		"a 3-byte counter, starting with a random value.",
	Serialize:  serializeObjectID,
	ParseValue: unserializeObjectID,
	ParseLiteral: func(valueAST ast.Value) interface{} {
		switch valueAST := valueAST.(type) {
		case *ast.StringValue:
			return unserializeObjectID(valueAST.Value)
		}
		return nil
	},
})
View Source
var TypeArticle = graphql.NewObject(
	graphql.ObjectConfig{
		Name: "Article",
		Fields: graphql.Fields{
			"id": &FieldID,
			"name": &graphql.Field{
				Type: graphql.String,
			},
			"description": &graphql.Field{
				Type: graphql.String,
			},
			"price": &graphql.Field{
				Type: graphql.Float,
			},
			"images": &graphql.Field{
				Type: graphql.NewList(ObjectID),
			},
			"category": &graphql.Field{
				Type: graphql.String,
			},
			"rating": &graphql.Field{
				Type: graphql.Int,
			},
			"createdAt": &graphql.Field{
				Type: graphql.Int,
			},
			"updatedAt": &graphql.Field{
				Type: graphql.Int,
			},
			"stock": &graphql.Field{
				Type: graphql.NewList(TypeArticleStock),
			},
		},
	},
)

TypeArticle

View Source
var TypeArticleConnection = utils.ConnectionDefinitions(utils.ConnectionConfig{
	Name:     "Article",
	NodeType: TypeArticle,
})
View Source
var TypeArticleStock = graphql.NewObject(
	graphql.ObjectConfig{
		Name:        "ArticleStock",
		Description: "ArticleStock",
		Fields: graphql.Fields{
			"size": &graphql.Field{
				Type: graphql.String,
			},
			"id": &graphql.Field{
				Type: ObjectID,
			},
			"createdAt": &graphql.Field{
				Type: graphql.Int,
			},
		},
	},
)
View Source
var TypeArticleStockOrder = graphql.NewObject(
	graphql.ObjectConfig{
		Name:        "ArticleStockOrder",
		Description: "ArticleStock",
		Fields: graphql.Fields{
			"size": &graphql.Field{
				Type: graphql.String,
			},
			"count": &graphql.Field{
				Type: graphql.Int,
			},
			"refs": &graphql.Field{
				Type: graphql.NewList(TypeArticleStockOrderItem),
			},
		},
	},
)
View Source
var TypeArticleStockOrderItem = graphql.NewObject(
	graphql.ObjectConfig{
		Name:        "ArticleStockOrderItem",
		Description: "ArticleStock",
		Fields: graphql.Fields{
			"id": &graphql.Field{
				Type: ObjectID,
			},
			"state": &graphql.Field{
				Type: graphql.Int,
			},
			"order": &graphql.Field{
				Type: ObjectID,
			},
		},
	},
)
View Source
var TypeDistinct = graphql.ObjectConfig{
	Name: "Pepesito",
	Fields: graphql.Fields{
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"count": &graphql.Field{
			Type: graphql.Int,
		},
	},
}
View Source
var TypeOrder = graphql.NewObject(
	graphql.ObjectConfig{
		Name:        "Order",
		Description: "A ship in the Star Wars saga",
		Fields: graphql.Fields{
			"id":    &FieldID,
			"stock": &FieldStock,
			"user":  &FieldUser,
			"state": &graphql.Field{
				Type: graphql.Int,
			},
			"notes": &graphql.Field{
				Type: graphql.String,
			},
			"createdAt": &graphql.Field{
				Type: graphql.Int,
			},
			"updatedAt": &graphql.Field{
				Type: graphql.Int,
			},
		},
	},
)

TypeOrder

View Source
var TypeOrderConnection = utils.ConnectionDefinitions(utils.ConnectionConfig{
	Name:     "Order",
	NodeType: TypeOrder,
})

TypeOrderConnection

View Source
var TypeStock = graphql.NewObject(
	graphql.ObjectConfig{
		Name: "Stock",
		Fields: graphql.Fields{
			"id":      &FieldID,
			"article": &FieldArticle,
			"size": &graphql.Field{
				Type: graphql.String,
			},
			"createdAt": &graphql.Field{
				Type: graphql.Int,
			},
		},
	},
)

TypeStock

View Source
var TypeUpload = graphql.NewScalar(graphql.ScalarConfig{
	Name:        "Upload",
	Description: "Scalar upload object",
})
View Source
var TypeUser = graphql.NewObject(
	graphql.ObjectConfig{
		Name: "User",
		Fields: graphql.Fields{
			"id": &FieldID,
			"name": &graphql.Field{
				Type: graphql.String,
			},
			"surname": &graphql.Field{
				Type: graphql.String,
			},
			"email": &graphql.Field{
				Type: graphql.String,
			},
			"phone": &graphql.Field{
				Type: graphql.String,
			},
			"address": &graphql.Field{
				Type: graphql.String,
			},
		},
	},
)

TypeUser

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL