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

Method toGraphqlJSON

query/outputnode.go:1235–1268  ·  view source on GitHub ↗
(genc *graphQLEncoder, n fastJsonNode, f gqlSchema.Field)

Source from the content-addressed store, hash-verified

1233}
1234
1235func (sg *SubGraph) toGraphqlJSON(genc *graphQLEncoder, n fastJsonNode, f gqlSchema.Field) error {
1236 // GraphQL queries will always have at least one query whose results are visible to users,
1237 // implying that the root fastJson node will always have at least one child. So, no need
1238 // to check for the case where there are no children for the root fastJson node.
1239
1240 // if this field has any @custom(http: {...}) children,
1241 // then need to resolve them first before encoding the final GraphQL result.
1242 genc.processCustomFields(f, n)
1243 // now encode the GraphQL results.
1244 if !genc.encode(encodeInput{
1245 parentField: nil,
1246 parentPath: f.PreAllocatePathSlice(),
1247 fj: n,
1248 fjIsRoot: true,
1249 childSelSet: []gqlSchema.Field{f},
1250 }) {
1251 // if genc.encode() didn't finish successfully here, that means we need to send
1252 // data as null in the GraphQL response like this:
1253 // {
1254 // "errors": [...],
1255 // "data": null
1256 // }
1257 // and not just null for a single query in data.
1258 // So, reset the buffer contents here, so that GraphQL layer may know that if it gets
1259 // error of type x.GqlErrorList along with nil JSON response, then it needs to set whole
1260 // data as null.
1261 genc.buf.Reset()
1262 }
1263
1264 if len(genc.errs) > 0 {
1265 return genc.errs
1266 }
1267 return nil
1268}
1269
1270func (sg *SubGraph) fieldName() string {
1271 fieldName := sg.Attr

Callers 1

toFastJSONMethod · 0.95

Calls 4

processCustomFieldsMethod · 0.80
PreAllocatePathSliceMethod · 0.65
encodeMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected