:doc:`AppSync <../../appsync>` / Client / evaluate_code

*************
evaluate_code
*************



.. py:method:: AppSync.Client.evaluate_code(**kwargs)

  

  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.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/appsync-2017-07-25/EvaluateCode>`_  


  **Request Syntax**
  ::

    response = client.evaluate_code(
        runtime={
            'name': 'APPSYNC_JS',
            'runtimeVersion': 'string'
        },
        code='string',
        context='string',
        function='string'
    )
    
  :type runtime: dict
  :param runtime: **[REQUIRED]** 

    The runtime to be used when evaluating the code. Currently, only the ``APPSYNC_JS`` runtime is supported.

    

  
    - **name** *(string) --* **[REQUIRED]** 

      The ``name`` of the runtime to use. Currently, the only allowed value is ``APPSYNC_JS``.

      

    
    - **runtimeVersion** *(string) --* **[REQUIRED]** 

      The ``version`` of the runtime to use. Currently, the only allowed version is ``1.0.0``.

      

    
  
  :type code: string
  :param code: **[REQUIRED]** 

    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 context: string
  :param context: **[REQUIRED]** 

    The map that holds all of the contextual information for your resolver invocation. A ``context`` is required for this action.

    

  
  :type function: string
  :param function: 

    The function within the code to be evaluated. If provided, the valid values are ``request`` and ``response``.

    

  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {
          'evaluationResult': 'string',
          'error': {
              'message': 'string',
              'codeErrors': [
                  {
                      'errorType': 'string',
                      'value': 'string',
                      'location': {
                          'line': 123,
                          'column': 123,
                          'span': 123
                      }
                  },
              ]
          },
          'logs': [
              'string',
          ],
          'stash': 'string',
          'outErrors': 'string'
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **evaluationResult** *(string) --* 

        The result of the evaluation operation.

        
      

      - **error** *(dict) --* 

        Contains the payload of the response error.

        
        

        - **message** *(string) --* 

          The error payload.

          
        

        - **codeErrors** *(list) --* 

          Contains the list of ``CodeError`` objects.

          
          

          - *(dict) --* 

            Describes an AppSync error.

            
            

            - **errorType** *(string) --* 

              The type of code error.

               

              Examples include, but aren't limited to: ``LINT_ERROR``, ``PARSER_ERROR``.

              
            

            - **value** *(string) --* 

              A user presentable error.

               

              Examples include, but aren't limited to: ``Parsing error: Unterminated string literal``.

              
            

            - **location** *(dict) --* 

              The line, column, and span location of the error in the code.

              
              

              - **line** *(integer) --* 

                The line number in the code. Defaults to ``0`` if unknown.

                
              

              - **column** *(integer) --* 

                The column number in the code. Defaults to ``0`` if unknown.

                
              

              - **span** *(integer) --* 

                The span/length of the error. Defaults to ``-1`` if unknown.

                
          
        
      
    
      

      - **logs** *(list) --* 

        A list of logs that were generated by calls to ``util.log.info`` and ``util.log.error`` in the evaluated code.

        
        

        - *(string) --* 
    
      

      - **stash** *(string) --* 

        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.

        
      

      - **outErrors** *(string) --* 

        The list of runtime errors that are added to the GraphQL operation response.

        
  
  **Exceptions**
  
  *   :py:class:`AppSync.Client.exceptions.AccessDeniedException`

  
  *   :py:class:`AppSync.Client.exceptions.InternalFailureException`

  
  *   :py:class:`AppSync.Client.exceptions.BadRequestException`

  