dgraph-io/dgraph · error

while substituting vars in URL

Error message

while substituting vars in URL

What it means

When resolving a field backed by a remote (federation/custom) GraphQL endpoint, URL template variables in fconf.URL are substituted from the field's argument map via SubstituteVarsInURL. This error is wrapped when that substitution fails — typically because a required URL variable has no matching argument value.

Source

Thrown at graphql/schema/wrappers.go:1569

		fconf.RemoteGqlQueryName = qfield.Name
		buf := &bytes.Buffer{}
		buildGraphqlRequestFields(buf, f.field)
		remoteQuery := graphqlArg.Raw
		remoteQuery = remoteQuery[:strings.LastIndex(remoteQuery, "}")]
		remoteQuery = fmt.Sprintf("%s%s}", remoteQuery, buf.String())
		fconf.RemoteGqlQuery = remoteQuery
	}

	// if it is a query or mutation, substitute the vars in URL and Body here itself
	if isQueryOrMutation {
		var err error
		argMap := f.field.ArgumentMap(f.op.vars)
		var bodyVars map[string]interface{}
		// url params can exist only with body, and not with graphql
		if graphqlArg == nil {
			fconf.URL, err = SubstituteVarsInURL(fconf.URL, argMap)
			if err != nil {
				return nil, errors.Wrapf(err, "while substituting vars in URL")
			}
			bodyVars = argMap
		} else {
			bodyVars = make(map[string]interface{})
			bodyVars["query"] = fconf.RemoteGqlQuery
			bodyVars["variables"] = argMap
		}
		fconf.Template = SubstituteVarsInBody(fconf.Template, bodyVars)
	}
	return fconf, nil
}

func (f *field) CustomHTTPConfig() (*FieldHTTPConfig, error) {
	return getCustomHTTPConfig(f, false)
}

func (f *field) EnumValues() []string {
	typ := f.Type()

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure every `{{var}}` in the remote URL matches a field argument name
  2. Check the wrapped error for which variable failed to substitute
  3. Fix the @remote/custom config so URL params align with the schema arguments

Example fix

// before
url: "http://svc:8080/product/{{id}"
// after
url: "http://svc:8080/product/{{id}}"
Defensive patterns

Strategy: validation

Validate before calling

vars := regexp.MustCompile(`\{\{([^}]+)\}\}`).FindAllStringSubmatch(conf.URL, -1)
for _, v := range vars {
	if _, ok := args[v[1]]; !ok { return fmt.Errorf("missing URL var %s", v[1]) }
}

Try / catch

res, err := field.Resolve(...)
if err != nil && strings.Contains(err.Error(), "while substituting vars in URL") {
	log.Errorf("remote URL template vars mismatch: %v", err)
	return nil, err
}

Prevention

When it happens

Trigger: Executing a query whose remote resolution config has a URL with `{{var}}` placeholders while graphqlArg is nil, and argMap lacks the variable or the value is incompatible with substitution.

Common situations: RemoteGraphQL URL templating mismatched with the field's arguments; renaming an argument without updating the URL template; nil/missing argument values at query time.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/c6e4f87594092fae. Report an issue: GitHub.