types

package
v0.0.0-...-f501c68 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AccessType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Access",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.Access)
				return md.Id.Hex(), nil
			},
		},
		"view": &graphql.Field{
			Type: ViewType,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.Access)
				v, err := services.ViewOfUser(md.View)
				return *v, err
			},
		},
		"order": &graphql.Field{
			Type: graphql.Int,
		},
		"position": &graphql.Field{
			Type: graphql.String,
		},
	},
})
View Source
var ModuleType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Module",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.Module)
				return md.Id.Hex(), nil
			},
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"icon": &graphql.Field{
			Type: graphql.String,
		},
		"color": &graphql.Field{
			Type: graphql.String,
		},
		"roles": &graphql.Field{
			Type: graphql.NewList(RoleType),
		},
		"views": &graphql.Field{
			Type: graphql.NewList(ViewType),
		},
	},
})
View Source
var OperationType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Operation",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.ID,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.Operation)
				return md.Id.Hex(), nil
			},
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"description": &graphql.Field{
			Type: graphql.String,
		},
		"crud": &graphql.Field{
			Type: graphql.Int,
		},
	},
})
View Source
var RoleType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Role",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.Role)
				return md.Id.Hex(), nil
			},
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"description": &graphql.Field{
			Type: graphql.String,
		},
		"accesses": &graphql.Field{
			Type: graphql.NewList(AccessType),
		},
	},
})

User Generic

View Source
var UserType = graphql.NewObject(graphql.ObjectConfig{
	Name: "User",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.User)
				return md.Id.Hex(), nil
			},
		},
		"names": &graphql.Field{
			Type: graphql.String,
		},
		"ln": &graphql.Field{
			Type: graphql.String,
		},
		"mln": &graphql.Field{
			Type: graphql.String,
		},
		"dni": &graphql.Field{
			Type: graphql.String,
		},
		"photo": &graphql.Field{
			Type: graphql.String,
		},
		"nick": &graphql.Field{
			Type: graphql.String,
		},
		"email": &graphql.Field{
			Type: graphql.String,
		},

		"token": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.User)
				token, _ := services.CreateTokenString(md.Id.Hex())
				if token == "" {
					return nil, nil
				}
				return token, nil
			},
		},
		"modules": &graphql.Field{
			Type: graphql.NewList(ModuleType),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.User)
				modules, err := services.ModulesOfUser(md.Roles)
				if err != nil {
					return nil, err
				}
				return *modules, nil
			},
		},
		"roles": &graphql.Field{
			Type: graphql.NewList(RoleType),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				user, _ := p.Source.(models.User)
				return services.GetRolesOfUser(user.Roles)
			},
		},
	},
})
View Source
var ViewType = graphql.NewObject(graphql.ObjectConfig{
	Name: "View",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.String,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.View)
				return md.Id.Hex(), nil
			},
		},
		"name": &graphql.Field{
			Type: graphql.String,
		},
		"description": &graphql.Field{
			Type: graphql.String,
		},
		"url": &graphql.Field{
			Type: graphql.String,
		},
		"icon": &graphql.Field{
			Type: graphql.String,
		},
		"operations": &graphql.Field{
			Type: graphql.NewList(OperationType),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				md, _ := p.Source.(models.View)
				return services.GetOperationsByIDs(md.Operations)
			},
		},
	},
})

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