

# EvaluateCode
<a name="API_EvaluateCode"></a>

Evaluates the given code and returns the response. The code definition requirements depend on the specified runtime. For `APPSYNC_JS` runtimes, the code defines the request and response functions. The request function takes the incoming request after a GraphQL operation is parsed and converts it into a request configuration for the selected data source operation. The response function interprets responses from the data source and maps it to the shape of the GraphQL field output type. 

## Request Syntax
<a name="API_EvaluateCode_RequestSyntax"></a>

```
POST /v1/dataplane-evaluatecode HTTP/1.1
Content-type: application/json

{
   "code": "string",
   "context": "string",
   "function": "string",
   "runtime": { 
      "name": "string",
      "runtimeVersion": "string"
   }
}
```

## URI Request Parameters
<a name="API_EvaluateCode_RequestParameters"></a>

The request does not use any URI parameters.

## Request Body
<a name="API_EvaluateCode_RequestBody"></a>

The request accepts the following data in JSON format.

 ** [code](#API_EvaluateCode_RequestSyntax) **   <a name="appsync-EvaluateCode-request-code"></a>
The code definition to be evaluated. Note that `code` and `runtime` are both required for this action. The `runtime` value must be `APPSYNC_JS`.  
Type: String  
Length Constraints: Minimum length of 1. Maximum length of 32768.  
Required: Yes

 ** [context](#API_EvaluateCode_RequestSyntax) **   <a name="appsync-EvaluateCode-request-context"></a>
The map that holds all of the contextual information for your resolver invocation. A `context` is required for this action.  
Type: String  
Length Constraints: Minimum length of 2. Maximum length of 28000.  
Pattern: `^[\s\S]*$`   
Required: Yes

 ** [function](#API_EvaluateCode_RequestSyntax) **   <a name="appsync-EvaluateCode-request-function"></a>
The function within the code to be evaluated. If provided, the valid values are `request` and `response`.  
Type: String  
Required: No

 ** [runtime](#API_EvaluateCode_RequestSyntax) **   <a name="appsync-EvaluateCode-request-runtime"></a>
The runtime to be used when evaluating the code. Currently, only the `APPSYNC_JS` runtime is supported.  
Type: [AppSyncRuntime](API_AppSyncRuntime.md) object  
Required: Yes

## Response Syntax
<a name="API_EvaluateCode_ResponseSyntax"></a>

```
HTTP/1.1 200
Content-type: application/json

{
   "error": { 
      "codeErrors": [ 
         { 
            "errorType": "string",
            "location": { 
               "column": number,
               "line": number,
               "span": number
            },
            "value": "string"
         }
      ],
      "message": "string"
   },
   "evaluationResult": "string",
   "logs": [ "string" ],
   "outErrors": "string",
   "stash": "string"
}
```

## Response Elements
<a name="API_EvaluateCode_ResponseElements"></a>

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

 ** [error](#API_EvaluateCode_ResponseSyntax) **   <a name="appsync-EvaluateCode-response-error"></a>
Contains the payload of the response error.  
Type: [EvaluateCodeErrorDetail](API_EvaluateCodeErrorDetail.md) object

 ** [evaluationResult](#API_EvaluateCode_ResponseSyntax) **   <a name="appsync-EvaluateCode-response-evaluationResult"></a>
The result of the evaluation operation.  
Type: String  
Length Constraints: Minimum length of 0. Maximum length of 65536.  
Pattern: `^[\s\S]*$` 

 ** [logs](#API_EvaluateCode_ResponseSyntax) **   <a name="appsync-EvaluateCode-response-logs"></a>
A list of logs that were generated by calls to `util.log.info` and `util.log.error` in the evaluated code.  
Type: Array of strings

 ** [outErrors](#API_EvaluateCode_ResponseSyntax) **   <a name="appsync-EvaluateCode-response-outErrors"></a>
The list of runtime errors that are added to the GraphQL operation response.  
Type: String  
Pattern: `^[\s\S]*$` 

 ** [stash](#API_EvaluateCode_ResponseSyntax) **   <a name="appsync-EvaluateCode-response-stash"></a>
An object available inside each resolver and function handler. A single `stash` object lives through a single resolver run. Therefore, you can use the stash to pass arbitrary data across request and response handlers and across functions in a pipeline resolver.  
Type: String  
Pattern: `^[\s\S]*$` 

## Errors
<a name="API_EvaluateCode_Errors"></a>

For information about the errors that are common to all actions, see [Common Error Types](CommonErrors.md).

 ** AccessDeniedException **   
You don't have access to perform this operation on this resource.  
HTTP Status Code: 403

 ** BadRequestException **   
The request is not well formed. For example, a value is invalid or a required field is missing. Check the field values, and then try again.    
 ** detail **   
Provides further details for the reason behind the bad request. For reason type `CODE_ERROR`, the detail will contain a list of code errors.  
 ** reason **   
Provides context for the cause of the bad request. The only supported value is `CODE_ERROR`.
HTTP Status Code: 400

 ** InternalFailureException **   
An internal AWS AppSync error occurred. Try your request again.  
HTTP Status Code: 500

## See Also
<a name="API_EvaluateCode_SeeAlso"></a>

For more information about using this API in one of the language-specific AWS SDKs, see the following:
+  [AWS Command Line Interface V2](https://docs.aws.amazon.com/goto/cli2/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for .NET V4](https://docs.aws.amazon.com/goto/DotNetSDKV4/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for C\$1\$1](https://docs.aws.amazon.com/goto/SdkForCpp/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for Go v2](https://docs.aws.amazon.com/goto/SdkForGoV2/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for Java V2](https://docs.aws.amazon.com/goto/SdkForJavaV2/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/goto/SdkForJavaScriptV3/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for Kotlin](https://docs.aws.amazon.com/goto/SdkForKotlin/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for PHP V3](https://docs.aws.amazon.com/goto/SdkForPHPV3/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for Python](https://docs.aws.amazon.com/goto/boto3/appsync-2017-07-25/EvaluateCode) 
+  [AWS SDK for Ruby V3](https://docs.aws.amazon.com/goto/SdkForRubyV3/appsync-2017-07-25/EvaluateCode) 