References

References target previously defined or received properties. References are strictly typed.

Introduction

References are defined inside a template definition. References contain two parts. The resource to be targeted and the path within the given resource.

{{ input:message }}

A error is returned if the given resource/path has not been found or when types mismatch

Resources

Calls, inputs and outputs are resources inside a flow. All resources could be referenced. Below is a simple flow with the following resources available: input and user.

flow "fetch" {
	input "schema.Query" {}
	
	resource "user" {}
	
	output "schema.Result" {
		message = "{{ input:message }}"
	}
}

Properties

Inside a resource are properties available. The available properties inside a resource might differ. Below are the available properties within different resource types. The request property is always used as default if no property is defined.

{{ call.request:prop }}

Input

Call

header

header

request

request

response

flow "fetch" {
	input "schema.Query" {}
	
	resource "schema" {
		request "schema.User" "GetUser" {
			message = "{{ input:message }}"
		}
	}
	
	output "schema.Result" {
		message = "{{ user.request:message }}"
	}
}

Path

Properties and nested properties are simply defined through the reference path.

flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "schema.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.User" {
		message "address" {
			street = "{{ user.request:address.street }}"
		}
	}
}

Message reference

Complete messages could be referenced if the content is mappable with the target property. This could be useful to reference complete objects without having to define a object over and over again.

Inside the example below is the address message copied to the output.

flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "proto.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.User" {
		address = "{{ user.request:address }}"
	}
}

Self reference

Sometimes you want to copy the entire message of a given resource. This is similar to message references but could be applied to entire resources instead of properties.

Inside the example below is the user request message copied to the output inside the user property.

flow "create" {
	input "schema.CreateUser" {}

	resource "user" {
		request "schema.User" "New" {
			message "address" {
				street = "{{ input:street }}"
			}
		}
	}
	
	output "schema.UserDetails" {
		user = "{{ user.request:. }}"
	}
}

Nested values

Nested values (messages) store properties, nested values could be created inside nested values.

message "nested" {
    value = "{{ input:message }}"
}

Repeated values

Repeated messages accept two labels the first one is its property name and the second one is the resource reference. If a repeated message is kept empty the whole message is attempted to be copied.

repeated "destination" "input:destination" {
    country = "{{ input:destination.country }}"
}

Currently are only repeated messages supported, repeated values are planned for in the future

Header values

Headers could be defined and passed similar to message properties. Header values are accessed through the header resource property.

input "schema.Object" {
    header = ["Authorization"]
}

resource "authenticate" {
    request "service" "Auth" {
        header {
            Authorization = "{{ input.header:Authorization }}"
        }
    }
}

Last updated