MCPcopy
hub / github.com/dgraph-io/dgraph / ToJson

Function ToJson

query/outputnode.go:40–62  ·  view source on GitHub ↗

ToJson converts the list of subgraph into a JSON response by calling toFastJSON.

(ctx context.Context, l *Latency, sgl []*SubGraph, field gqlSchema.Field)

Source from the content-addressed store, hash-verified

38
39// ToJson converts the list of subgraph into a JSON response by calling toFastJSON.
40func ToJson(ctx context.Context, l *Latency, sgl []*SubGraph, field gqlSchema.Field) ([]byte,
41 error) {
42 sgr := &SubGraph{}
43 for _, sg := range sgl {
44 if sg.Params.Alias == "var" || sg.Params.Alias == "shortest" {
45 continue
46 }
47 if sg.Params.GetUid {
48 sgr.Params.GetUid = true
49 }
50 sgr.Children = append(sgr.Children, sg)
51 }
52 data, err := sgr.toFastJSON(ctx, l, field)
53
54 // don't log or wrap GraphQL errors
55 if x.IsGqlErrorList(err) {
56 return data, err
57 }
58 if err != nil {
59 glog.Errorf("while running ToJson: %v\n", err)
60 }
61 return data, errors.Wrapf(err, "while running ToJson")
62}
63
64// We are capping maxEncoded size to 4GB, as grpc encoding fails
65// for a response size > math.MaxUint32.

Callers 3

processQueryFunction · 0.92
processToFastJSONFunction · 0.92
assertJSONFunction · 0.85

Calls 3

toFastJSONMethod · 0.95
IsGqlErrorListFunction · 0.92
ErrorfMethod · 0.45

Tested by 2

processToFastJSONFunction · 0.74
assertJSONFunction · 0.68