MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / getCustomHTTPConfig

Function getCustomHTTPConfig

graphql/schema/wrappers.go:1482–1580  ·  view source on GitHub ↗
(f *field, isQueryOrMutation bool)

Source from the content-addressed store, hash-verified

1480}
1481
1482func getCustomHTTPConfig(f *field, isQueryOrMutation bool) (*FieldHTTPConfig, error) {
1483 custom := f.op.inSchema.customDirectives[f.GetObjectName()][f.Name()]
1484 httpArg := custom.Arguments.ForName(httpArg)
1485 fconf := &FieldHTTPConfig{
1486 URL: httpArg.Value.Children.ForName(httpUrl).Raw,
1487 Method: httpArg.Value.Children.ForName(httpMethod).Raw,
1488 }
1489
1490 fconf.Mode = SINGLE
1491 op := httpArg.Value.Children.ForName(mode)
1492 if op != nil {
1493 fconf.Mode = op.Raw
1494 }
1495
1496 // both body and graphql can't be present together
1497 bodyArg := httpArg.Value.Children.ForName(httpBody)
1498 graphqlArg := httpArg.Value.Children.ForName(httpGraphql)
1499 var bodyTemplate string
1500 if bodyArg != nil {
1501 bodyTemplate = bodyArg.Raw
1502 } else if graphqlArg != nil {
1503 bodyTemplate = `{ query: $query, variables: $variables }`
1504 }
1505 // bodyTemplate will be empty if there was no body or graphql, like the case of a simple GET req
1506 if bodyTemplate != "" {
1507 bt, _, err := parseBodyTemplate(bodyTemplate, true)
1508 if err != nil {
1509 return nil, err
1510 }
1511 fconf.Template = bt
1512 }
1513
1514 fconf.ForwardHeaders = http.Header{}
1515 // set application/json as the default Content-Type
1516 fconf.ForwardHeaders.Set("Content-Type", "application/json")
1517 secretHeaders := httpArg.Value.Children.ForName("secretHeaders")
1518 if secretHeaders != nil {
1519 for _, h := range secretHeaders.Children {
1520 key := strings.Split(h.Value.Raw, ":")
1521 if len(key) == 1 {
1522 key = []string{h.Value.Raw, h.Value.Raw}
1523 }
1524 val := string(f.op.inSchema.meta.secrets[key[1]])
1525 fconf.ForwardHeaders.Set(key[0], val)
1526 }
1527 }
1528
1529 forwardHeaders := httpArg.Value.Children.ForName("forwardHeaders")
1530 if forwardHeaders != nil {
1531 for _, h := range forwardHeaders.Children {
1532 key := strings.Split(h.Value.Raw, ":")
1533 if len(key) == 1 {
1534 key = []string{h.Value.Raw, h.Value.Raw}
1535 }
1536 reqHeaderVal := f.op.header.Get(key[1])
1537 fconf.ForwardHeaders.Set(key[0], reqHeaderVal)
1538 }
1539 }

Callers 3

CustomHTTPConfigMethod · 0.85
CustomHTTPConfigMethod · 0.85
CustomHTTPConfigMethod · 0.85

Calls 10

parseBodyTemplateFunction · 0.85
SubstituteVarsInURLFunction · 0.85
SubstituteVarsInBodyFunction · 0.85
GetObjectNameMethod · 0.65
NameMethod · 0.65
SetMethod · 0.65
GetMethod · 0.65
LastIndexMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…