Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var GQLGlobalOperationType = graphql.NewObject(graphql.ObjectConfig{ Name: "GlobalOperation", Description: "`GlobalOperation` contains all flamed global features", Fields: graphql.Fields{ "search": Search, "iterate": Iterate, "retrieve": Retrieve, "searchJ": SearchJ, }, })
View Source
var Iterate = &graphql.Field{ Name: "Iterate", Description: "Iterate data from the state store", Type: graphql.NewList(kind.GQLStateEntryResponse), Args: graphql.FieldConfigArgument{ "from": &graphql.ArgumentConfig{ Description: "State address or address prefix in hex string format", Type: graphql.String, }, "prefix": &graphql.ArgumentConfig{ Description: "State address prefix in hex string format", Type: graphql.String, }, "limit": &graphql.ArgumentConfig{ Description: "Limit", Type: graphql.NewNonNull(kind.GQLUInt64Type), }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { from := "" if p.Args["from"] != nil { from = p.Args["from"].(string) } prefix := "" if p.Args["prefix"] != nil { prefix = p.Args["prefix"].(string) } limit := p.Args["limit"].(*kind.UInt64) ctx, ok := p.Source.(*context.GlobalOperationContext) if !ok { return nil, nil } if !utility.HasGlobalIteratePermission(ctx.AccessControl) { return nil, gqlerrors.NewFormattedError(x.ErrGlobalIteratePermissionRequired.Error()) } o, err := ctx.GlobalOperation.Iterate(from, prefix, limit.Value()) if err != nil { return nil, gqlerrors.NewFormattedError(err.Error()) } return o, nil }, }
View Source
var Retrieve = &graphql.Field{ Name: "Retrieve", Description: "Retrieve data from the state store", Type: graphql.NewList(kind.GQLStateEntryResponse), Args: graphql.FieldConfigArgument{ "addresses": &graphql.ArgumentConfig{ Description: "Address in hex string format", Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(graphql.String))), }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { addresses := p.Args["addresses"].([]interface{}) ctx, ok := p.Source.(*context.GlobalOperationContext) if !ok { return nil, nil } if !utility.HasGlobalRetrievePermission(ctx.AccessControl) { return nil, gqlerrors.NewFormattedError(x.ErrGlobalRetrievePermissionRequired.Error()) } o, err := ctx.GlobalOperation.Retrieve(addresses) if err != nil { return nil, gqlerrors.NewFormattedError(err.Error()) } return o, nil }, }
View Source
var Search = &graphql.Field{ Name: "Search", Description: "Search in the index store", Type: kind.GQLSearchResponse, Args: graphql.FieldConfigArgument{ "input": &graphql.ArgumentConfig{ Description: "Search input", Type: graphql.NewNonNull(kind.GQLSearchInputType), }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { input := p.Args["input"].(map[string]interface{}) ctx, ok := p.Source.(*context.GlobalOperationContext) if !ok { return nil, nil } if !utility.HasGlobalSearchPermission(ctx.AccessControl) { return nil, gqlerrors.NewFormattedError(x.ErrGlobalSearchPermissionRequired.Error()) } globalSearchInput := &pb.GlobalSearchInput{ Namespace: []byte(ctx.GlobalOperation.Namespace()), } globalSearchInput.Query = &pb.GlobalSearchInput_QueryString{ QueryString: &pb.QueryString{Q: input["query"].(string)}, } if v, ok := input["size"].(int); ok { globalSearchInput.Size = int32(v) } else { globalSearchInput.Size = 20 } if v, ok := input["from"].(int); ok { globalSearchInput.From = int32(v) } else { globalSearchInput.From = 0 } if v, ok := input["includeLocations"].(bool); ok { globalSearchInput.IncludeLocations = v } if v, ok := input["explain"].(bool); ok { globalSearchInput.Explain = v } if v, ok := input["fields"].([]interface{}); ok { for _, field := range v { globalSearchInput.Fields = append(globalSearchInput.Fields, field.(string)) } } if v, ok := input["sort"].([]interface{}); ok { for _, field := range v { globalSearchInput.Sort = append(globalSearchInput.Sort, field.(string)) } } if v, ok := input["highlight"].(bool); ok { globalSearchInput.Highlight = v } if v, ok := input["highlightFields"].([]interface{}); ok { for _, field := range v { globalSearchInput.HighlightFields = append(globalSearchInput.HighlightFields, field.(string)) } } if v, ok := input["highlightStyle"].(string); ok { globalSearchInput.HighlightStyle = v } if facets, ok := input["facets"].([]interface{}); ok { for _, facet := range facets { if v, ok := facet.(map[string]interface{}); ok { pf := &pb.Facet{} pf.Name = v["name"].(string) pf.Field = v["field"].(string) pf.Size = int32(v["size"].(int)) if v2, ok := v["dateTimeRangeFacets"].([]interface{}); ok { for _, v3 := range v2 { if v4, ok := v3.(map[string]interface{}); ok { d := &pb.DateTimeRangeFacet{} d.Name = v4["name"].(string) d.Start = v4["start"].(string) d.End = v4["end"].(string) pf.DateTimeRangeFacets = append(pf.DateTimeRangeFacets, d) } } } if v2, ok := v["numericRangeFacets"].([]interface{}); ok { for _, v3 := range v2 { if v4, ok := v3.(map[string]interface{}); ok { d := &pb.NumericRangeFacet{} d.Name = v4["name"].(string) d.Min = v4["min"].(float64) d.Max = v4["max"].(float64) pf.NumericRangeFacets = append(pf.NumericRangeFacets, d) } } } globalSearchInput.Facets = append(globalSearchInput.Facets, pf) } } } o, err := ctx.GlobalOperation.Search(globalSearchInput) if err != nil { return nil, gqlerrors.NewFormattedError(err.Error()) } if o != nil { return o.ToSearchResponse(), nil } return nil, nil }, }
View Source
var SearchJ = &graphql.Field{ Name: "SearchJ", Description: "Search and get json response", Type: kind.GQLJSONType, Args: graphql.FieldConfigArgument{ "input": &graphql.ArgumentConfig{ Description: "Search input", Type: graphql.NewNonNull(kind.GQLSearchInputType), }, }, Resolve: func(p graphql.ResolveParams) (interface{}, error) { input := p.Args["input"].(map[string]interface{}) ctx, ok := p.Source.(*context.GlobalOperationContext) if !ok { return nil, nil } if !utility.HasGlobalSearchPermission(ctx.AccessControl) { return nil, gqlerrors.NewFormattedError(x.ErrGlobalSearchPermissionRequired.Error()) } globalSearchInput := &pb.GlobalSearchInput{ Namespace: []byte(ctx.GlobalOperation.Namespace()), } globalSearchInput.Query = &pb.GlobalSearchInput_QueryString{ QueryString: &pb.QueryString{Q: input["query"].(string)}, } if v, ok := input["size"].(int); ok { globalSearchInput.Size = int32(v) } else { globalSearchInput.Size = 20 } if v, ok := input["from"].(int); ok { globalSearchInput.From = int32(v) } else { globalSearchInput.From = 0 } if v, ok := input["includeLocations"].(bool); ok { globalSearchInput.IncludeLocations = v } if v, ok := input["explain"].(bool); ok { globalSearchInput.Explain = v } if v, ok := input["fields"].([]interface{}); ok { for _, field := range v { globalSearchInput.Fields = append(globalSearchInput.Fields, field.(string)) } } if v, ok := input["sort"].([]interface{}); ok { for _, field := range v { globalSearchInput.Sort = append(globalSearchInput.Sort, field.(string)) } } if v, ok := input["highlight"].(bool); ok { globalSearchInput.Highlight = v } if v, ok := input["highlightFields"].([]interface{}); ok { for _, field := range v { globalSearchInput.HighlightFields = append(globalSearchInput.HighlightFields, field.(string)) } } if v, ok := input["highlightStyle"].(string); ok { globalSearchInput.HighlightStyle = v } if facets, ok := input["facets"].([]interface{}); ok { for _, facet := range facets { if v, ok := facet.(map[string]interface{}); ok { pf := &pb.Facet{} pf.Name = v["name"].(string) pf.Field = v["field"].(string) pf.Size = int32(v["size"].(int)) if v2, ok := v["dateTimeRangeFacets"].([]interface{}); ok { for _, v3 := range v2 { if v4, ok := v3.(map[string]interface{}); ok { d := &pb.DateTimeRangeFacet{} d.Name = v4["name"].(string) d.Start = v4["start"].(string) d.End = v4["end"].(string) pf.DateTimeRangeFacets = append(pf.DateTimeRangeFacets, d) } } } if v2, ok := v["numericRangeFacets"].([]interface{}); ok { for _, v3 := range v2 { if v4, ok := v3.(map[string]interface{}); ok { d := &pb.NumericRangeFacet{} d.Name = v4["name"].(string) d.Min = v4["min"].(float64) d.Max = v4["max"].(float64) pf.NumericRangeFacets = append(pf.NumericRangeFacets, d) } } } globalSearchInput.Facets = append(globalSearchInput.Facets, pf) } } } o, err := ctx.GlobalOperation.Search(globalSearchInput) if err != nil { return nil, gqlerrors.NewFormattedError(err.Error()) } if o != nil { return o.ToMap(), nil } return nil, nil }, }
Functions ¶
func GlobalOperation ¶
func GlobalOperation(flamedContext *fContext.FlamedContext) *graphql.Field
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.