handler

package
v0.0.0-...-a468dfb Latest Latest
Warning

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

Go to latest
Published: May 7, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package handler implements a simple handler for http

Index

Constants

This section is empty.

Variables

View Source
var AuthType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Auth",
	Fields: graphql.Fields{
		"token": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if auth, ok := p.Source.(*model.Auth); ok {
					return auth.Token, nil
				}
				return nil, nil
			},
		},
		"user": &graphql.Field{
			Type: UserType,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if auth, ok := p.Source.(*model.Auth); ok {
					return &auth.User, nil
				}
				return nil, nil
			},
		},
	},
})

AuthType handler

View Source
var CommentType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Comment",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.NewNonNull(graphql.ID),
		},
		"title": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
		},
		"body": &graphql.Field{
			Type: graphql.NewNonNull(graphql.ID),
		},
		"created_at": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
		},
	},
})

CommentType handler

View Source
var MutationType = graphql.NewObject(graphql.ObjectConfig{
	Name: "MutationType",
	Fields: graphql.Fields{
		"createUser": &graphql.Field{
			Type:    UserType,
			Args:    createUserArgs,
			Resolve: createUser,
		},
		"login": &graphql.Field{
			Type:    AuthType,
			Args:    loginArgs,
			Resolve: login,
		},
		"removeUser": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    removeUserArgs,
			Resolve: removeUser,
		},
		"follow": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    followArgs,
			Resolve: follow,
		},
		"unfollow": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    unfollowArgs,
			Resolve: unfollow,
		},
		"createPost": &graphql.Field{
			Type:    PostType,
			Args:    createPostArgs,
			Resolve: createPost,
		},
		"removePost": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    removePostArgs,
			Resolve: removePost,
		},
		"updatePost": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    updatePostArgs,
			Resolve: updatePost,
		},
		"praisePost": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    praisePostArgs,
			Resolve: praisePost,
		},
		"unpraisePost": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    unpraisePostArgs,
			Resolve: unpraisePost,
		},
		"createComment": &graphql.Field{
			Type:    CommentType,
			Args:    createCommentArgs,
			Resolve: createComment,
		},
		"removeComment": &graphql.Field{
			Type:    graphql.Boolean,
			Args:    removeCommentArgs,
			Resolve: removeComment,
		},
	},
})

MutationType handler

View Source
var PostType = graphql.NewObject(graphql.ObjectConfig{
	Name: "Post",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type: graphql.NewNonNull(graphql.ID),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if post, ok := p.Source.(*model.Post); ok == true {
					return post.ID, nil
				}
				return nil, nil
			},
		},
		"title": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if post, ok := p.Source.(*model.Post); ok == true {
					return post.Title, nil
				}
				return nil, nil
			},
		},
		"body": &graphql.Field{
			Type: graphql.NewNonNull(graphql.ID),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if post, ok := p.Source.(*model.Post); ok == true {
					return post.Body, nil
				}
				return nil, nil
			},
		},
		"praise_num": &graphql.Field{
			Type: graphql.NewNonNull(graphql.Int),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if post, ok := p.Source.(*model.Post); ok == true {
					return post.PraiseNum, nil
				}
				return nil, nil
			},
		},
		"comment_num": &graphql.Field{
			Type: graphql.NewNonNull(graphql.Int),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if post, ok := p.Source.(*model.Post); ok == true {
					return post.CommentNum, nil
				}
				return nil, nil
			},
		},
		"createdate": &graphql.Field{
			Type:        graphql.NewNonNull(graphql.String),
			Description: "创建日期",
		},
	},
})

PostType handler

View Source
var QueryType = graphql.NewObject(graphql.ObjectConfig{
	Name: "QueryType",
	Fields: graphql.Fields{
		"user": &graphql.Field{
			Type:    UserType,
			Args:    userArgs,
			Resolve: getUserByID,
		},
	},
})

QueryType handler

View Source
var UserType = graphql.NewObject(graphql.ObjectConfig{
	Name: "User",
	Fields: graphql.Fields{
		"id": &graphql.Field{
			Type:        graphql.NewNonNull(graphql.ID),
			Description: "用户ID",
		},
		"nickname": &graphql.Field{
			Type:        graphql.NewNonNull(graphql.String),
			Description: "用户ID",
		},
		"email": &graphql.Field{
			Type:        graphql.NewNonNull(graphql.String),
			Description: "邮箱名称",
		},
		"created_at": &graphql.Field{
			Type:        graphql.String,
			Description: "创建日期",
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if user, ok := p.Source.(*model.User); ok == true {
					return user.CreatedAt, nil
				}
				return nil, nil
			},
		},
	},
})

UserType handler

Functions

func Handler

func Handler(schema graphql.Schema) http.HandlerFunc

Handler handler (已弃用,使用了官方自带的handler库)

Types

This section is empty.

Jump to

Keyboard shortcuts

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