Graphit allows you to define input parameters whereby the generated documents are executed using various settings like LUIs, LU table columns and other specific parameters that require processing.
Parameters can be set when:
Click :// in the Graphit window to open the Graphit Parameters dialog box.
Graphit Parameters are added to support the following:
Note that if the parameters have not been added to the Graphit Parameters dialog box, you can create a POST request for the Graphit file and add the parameters in the Request body. Alternatively, you can wrap the Graphit file using a Web Service and send the parameters to the Graphit file via the Web Service.
When creating a Graphit file, parameters can be defined using the ${} symbols to refer to the value that is set in the Parameters window. In this specific case, you must also define a Debug value in the Parameter window. If not, the response is empty.
Example:
The grSql.graphit file generates a JSON file that returns the values of the following fields:
The queries for the SELECT statements are:
The following screenshot displays the Graphit file:
Before running the file, a Debug value is assigned to the ${customer_id} and ${case_id} input parameters.
Click Run to see the results on the right side of the output window.
Add the parameters to the Parameters window to create a GET request for the Graphit file and populate the parameters in Swagger.
Note that to execute the Graphit file, first populate the parameter's value in Swagger. The Debug values are only taken as input in Debug mode.
Example:
Using the same grSql.graphit Graphit file as in the previous example, in the following screenshot the customer_id Debug value has been left empty intentionally.
As indicated below, the two Parameters fields are marked as required.
The customer_id=547 and case_id=1394 values are filled in the Parameters fields.
Note that when deleting all parameters in the Parameters dialog box together, the values in the GET section in the Swagger GUI cannot be specified but can be injected in the POST section, with a successful response upon execution.
A Graphit file can be invoked directly or be wrapped by a WS. When wrapped by a WS, the WS sends the parameters to Graphit which then parses them accordingly when generating the XML, JSON or CSV documents. The input parameters for the Graphit file can be populated by a parameter name or by a map object.
Example:
Map<String, Object> temp = new HashMap<>();
temp.put("input1",1000);
temp.put("input2",2463);
return graphit("grSql2.graphit", temp);
This code calls the following Graphit file which uses ${input1} and ${input2} as parameters for the customer_id and subscriber_id to populate the JSON output with relevant invoices:
Let's suppose you need to write a graphit file that retrieves data from a table and/or a field with dynamic names parsed from variables. In that case you can invoke the field name as a parameters in a Graphit node defined as non-prepared SQL statement.
For example, let's consider the following:
Parameters declaration window: customer_id is defined as string and is given the value 39.
Node defined as a function:
var fieldName = 'customer_id'
Node defined as SQL non-prepared:
select SSN from customer where ${fieldName} = ${customer_id}
In this case, the ${fieldName}
variable will be given the (string) value 'customer_id'
while the variable ${customer_id}
will be given the value 39
.
In that way, variables may be used in a graphit file (from a javascript function node) and hold the name of the field and the value to be processed to the WHERE statement.
See example in screenshot:
In addition, rather than defining the variable fieldName
within the javascript function node of your graphit file, you can define it in the java webservice that invokes the graphit file itself, and parse it as a map object as was shown in the previous section of this article.
Graphit allows you to define input parameters whereby the generated documents are executed using various settings like LUIs, LU table columns and other specific parameters that require processing.
Parameters can be set when:
Click :// in the Graphit window to open the Graphit Parameters dialog box.
Graphit Parameters are added to support the following:
Note that if the parameters have not been added to the Graphit Parameters dialog box, you can create a POST request for the Graphit file and add the parameters in the Request body. Alternatively, you can wrap the Graphit file using a Web Service and send the parameters to the Graphit file via the Web Service.
When creating a Graphit file, parameters can be defined using the ${} symbols to refer to the value that is set in the Parameters window. In this specific case, you must also define a Debug value in the Parameter window. If not, the response is empty.
Example:
The grSql.graphit file generates a JSON file that returns the values of the following fields:
The queries for the SELECT statements are:
The following screenshot displays the Graphit file:
Before running the file, a Debug value is assigned to the ${customer_id} and ${case_id} input parameters.
Click Run to see the results on the right side of the output window.
Add the parameters to the Parameters window to create a GET request for the Graphit file and populate the parameters in Swagger.
Note that to execute the Graphit file, first populate the parameter's value in Swagger. The Debug values are only taken as input in Debug mode.
Example:
Using the same grSql.graphit Graphit file as in the previous example, in the following screenshot the customer_id Debug value has been left empty intentionally.
As indicated below, the two Parameters fields are marked as required.
The customer_id=547 and case_id=1394 values are filled in the Parameters fields.
Note that when deleting all parameters in the Parameters dialog box together, the values in the GET section in the Swagger GUI cannot be specified but can be injected in the POST section, with a successful response upon execution.
A Graphit file can be invoked directly or be wrapped by a WS. When wrapped by a WS, the WS sends the parameters to Graphit which then parses them accordingly when generating the XML, JSON or CSV documents. The input parameters for the Graphit file can be populated by a parameter name or by a map object.
Example:
Map<String, Object> temp = new HashMap<>();
temp.put("input1",1000);
temp.put("input2",2463);
return graphit("grSql2.graphit", temp);
This code calls the following Graphit file which uses ${input1} and ${input2} as parameters for the customer_id and subscriber_id to populate the JSON output with relevant invoices:
Let's suppose you need to write a graphit file that retrieves data from a table and/or a field with dynamic names parsed from variables. In that case you can invoke the field name as a parameters in a Graphit node defined as non-prepared SQL statement.
For example, let's consider the following:
Parameters declaration window: customer_id is defined as string and is given the value 39.
Node defined as a function:
var fieldName = 'customer_id'
Node defined as SQL non-prepared:
select SSN from customer where ${fieldName} = ${customer_id}
In this case, the ${fieldName}
variable will be given the (string) value 'customer_id'
while the variable ${customer_id}
will be given the value 39
.
In that way, variables may be used in a graphit file (from a javascript function node) and hold the name of the field and the value to be processed to the WHERE statement.
See example in screenshot:
In addition, rather than defining the variable fieldName
within the javascript function node of your graphit file, you can define it in the java webservice that invokes the graphit file itself, and parse it as a map object as was shown in the previous section of this article.