How to implement User Defined Functions using get API

In the previous post, we have seen implementing User defined functions using find API.

Let’s check how to use the get API to read data using the User Defined Function.

Example

We have added data in the StudentInformation type in the previous post.
Here is a getStudentInfo function to read a record of a Student. It uses the get API to retrieve the details.

type Query {
getStudentInfo( type: HypiMutationType! id: String! ):HypiRootAggregate @tan(type:Groovy, inline: """return get(type, id)""")
}

Use hypi.id of the StudentInformation object as one of the UDF parameter to get details

Let’s execute the function.

{
  getStudentInfo(type:StudentInformation, id:"01FQNKWHFY409AG458YCQ36RV9") {
    ... on StudentInformation {
      hypi{
        id
        created
        updated
      }
      name
      dob
      standard
      address {
        door
        street
        city
      }
    }
  }
}
#result
{
  "data": {
    "getStudentInfo": {
      "hypi": {
        "id": "01FQNKWHFY409AG458YCQ36RV9",
        "created": "2021-12-24T07:01:06Z",
        "updated": "2021-12-24T07:01:06Z"
      },
      "name": "XYZ",
      "dob": "2011-05-07T00:00:00Z",
      "standard": "VII",
      "address": {
        "door": "23",
        "street": "3A Old Street",
        "city": "New Delhi"
      }
    }
  }
}