ToJson converts the list of subgraph into a JSON response by calling toFastJSON.
(ctx context.Context, l *Latency, sgl []*SubGraph, field gqlSchema.Field)
| 38 | |
| 39 | // ToJson converts the list of subgraph into a JSON response by calling toFastJSON. |
| 40 | func 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. |