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

Method writeCustomField

query/outputnode_graphql.go:581–600  ·  view source on GitHub ↗

writeCustomField is used to write the value when the currentSelection is a custom field. If the current field had @custom(http: {...}), then we need to find the fastJson node which stores data for this field from the customNodes mapping, and use that to write the value for this field.

(curSelection gqlSchema.Field,
	customNodes map[uint16]fastJsonNode, parentPath []interface{})

Source from the content-addressed store, hash-verified

579// stores data for this field from the customNodes mapping, and use that to write the value
580// for this field.
581func (genc *graphQLEncoder) writeCustomField(curSelection gqlSchema.Field,
582 customNodes map[uint16]fastJsonNode, parentPath []interface{}) bool {
583 if cNode := customNodes[genc.idForAttr(curSelection.DgraphAlias())]; cNode != nil {
584 // if we found the custom fastJson node, then directly write the value stored
585 // in that, as it would have been already completed.
586 val, err := genc.getScalarVal(cNode)
587 if err == nil {
588 x.Check2(genc.buf.Write(val))
589 // return true to indicate that the field was written successfully
590 return true
591 }
592
593 // if there was an error getting the value, append the error
594 genc.errs = append(genc.errs, curSelection.GqlErrorf(append(parentPath,
595 curSelection.ResponseName()), "%s", err.Error()))
596 }
597
598 // if no custom fastJson node was found or there was error getting the value, return false
599 return false
600}
601
602func (genc *graphQLEncoder) initChildAttrId(field gqlSchema.Field) {
603 for _, f := range field.SelectionSet() {

Callers 1

encodeMethod · 0.95

Calls 8

Check2Function · 0.92
idForAttrMethod · 0.80
getScalarValMethod · 0.80
DgraphAliasMethod · 0.65
WriteMethod · 0.65
GqlErrorfMethod · 0.65
ResponseNameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected