Evaluation of custom field failed while substituting variables into body for remote endpoint with an error

Sidenote: (can we add a custom tag here in discuss)

Version running: v2.0.0-rc1-518-g3c710183a

I have a lambda script which takes name parts and returns a single string concatenated string. This part works. I want to use this to make a custom field in my graphql endpoint. I first got hung up on the required ID field because my script does not require it but the custom field directive does. Here is where I am at now.

type Contact {
  id: ID!
  firstName: String
  middleName: String
  lastName: String
  organization: String
  abbreviation: String
  preferredName: String
  name: String @custom(http: {
    url: "https://mydomain.com/function-concatname"
    method: POST
    body: "{preferredName: $preferredName, organization: $organization, abbreviation: $abbreviation, firstName: $firstName, middleName: $middleName, lastName: $lastName}"
    secretHeaders: ["Content-type"]
  })
}
# Dgraph.Secret Content-type "application/json"

It successfully imports the schema, then I try to use it and it errors out with the following when queried:

Evaluation of custom field failed while substituting variables into body for remote endpoint with an error: couldn’t find variable: $lastName in variables map for field: name within type: Contact.

Well, this is a field in this type, but it is a nullable field.

According to the docs this should work

For both url and body templates, any non-null arguments or fields must be present to evaluate the custom logic. And the following rules are applied when building the request from the template for nullable arguments or fields.

  • If the value of a nullable argument is present, it’s used in the template.
  • If a nullable argument is present, but null, then in a body null is inserted, while in a url nothing is added. For example, if the desc argument above is null then { ..., storyLine: null, ...} is constructed for the body. Whereas, in a URL pattern like https://a.b.c/endpoint?arg=$gqlArg , if gqlArg is present, but null, the generated URL is https://a.b.c/endpoint?arg= .
  • If a nullable argument is not present, nothing is added to the URL/body. That would mean the constructed body would not contain storyLine if the desc argument is missing, and in https://a.b.c/endpoint?arg=$gqlArg the result would be https://a.b.c/endpoint if gqlArg were not present in the request arguments.

Thanks for filing this @amaster507. This seems like a bug. @JatinDevDG lets try and reproduce this as well and have a fix for this.

1 Like

@pawan this error is coming for master branch also.