jsontp

package
v0.0.0-...-4334ecd Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GQLGet = &graphql.Field{
	Name:        "Get",
	Type:        kind.GQLJSONType,
	Description: "",

	Args: graphql.FieldConfigArgument{
		"id": &graphql.ArgumentConfig{
			Description: "ID",
			Type:        graphql.NewNonNull(graphql.ID),
		},
	},

	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		id := p.Args["id"].(string)

		ikc, ok := p.Source.(*json.Context)
		if !ok {
			return nil, nil
		}

		if !utility.HasReadPermission(ikc.AccessControl) {
			return nil, gqlerrors.NewFormattedError(x.ErrReadPermissionRequired.Error())
		}

		obj := make(map[string]interface{})

		_, err := ikc.Client.Get(id, &obj)
		if err != nil {
			return nil, gqlerrors.NewFormattedError(err.Error())
		}
		return obj, nil
	},
}
View Source
var GQLGetList = &graphql.Field{
	Name:        "GetList",
	Type:        kind.GQLJSONType,
	Description: "",

	Args: graphql.FieldConfigArgument{
		"idList": &graphql.ArgumentConfig{
			Description: "List of id",
			Type:        graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.ID))),
		},
	},

	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		idList := p.Args["idList"].([]interface{})

		ikc, ok := p.Source.(*json.Context)
		if !ok {
			return nil, nil
		}

		if !utility.HasReadPermission(ikc.AccessControl) {
			return nil, gqlerrors.NewFormattedError(x.ErrReadPermissionRequired.Error())
		}

		obj, err := ikc.Client.GetList(idList)
		if err != nil {
			return nil, gqlerrors.NewFormattedError(err.Error())
		}
		return obj, nil
	},
}
View Source
var GQLGetListByIndexID = &graphql.Field{
	Name:        "GetListByIndexID",
	Type:        kind.GQLJSONType,
	Description: "",

	Args: graphql.FieldConfigArgument{
		"idList": &graphql.ArgumentConfig{
			Description: "List of index id",
			Type:        graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.String))),
		},
	},

	Resolve: func(p graphql.ResolveParams) (interface{}, error) {
		ids := p.Args["idList"].([]interface{})

		ikc, ok := p.Source.(*json.Context)
		if !ok {
			return nil, nil
		}

		if !utility.HasReadPermission(ikc.AccessControl) {
			return nil, gqlerrors.NewFormattedError(x.ErrReadPermissionRequired.Error())
		}

		obj, err := ikc.Client.GetListByIndexID(ids)
		if err != nil {
			return nil, gqlerrors.NewFormattedError(err.Error())
		}
		return obj, nil
	},
}
View Source
var GQLJSONTPType = graphql.NewObject(graphql.ObjectConfig{
	Name:        "JSONTP",
	Description: "JSON transaction processor",
	Fields: graphql.Fields{
		"get":              GQLGet,
		"getList":          GQLGetList,
		"getListByIndexID": GQLGetListByIndexID,
	},
})

Functions

func JSONTP

func JSONTP(flamedContext *fContext.FlamedContext) *graphql.Field

Types

This section is empty.

Jump to

Keyboard shortcuts

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