o
    ȳg                     @   sH   d dl Z d dlmZmZmZmZ d dlmZmZm	Z	 G dd deZ
dS )    N)AnyCallableDictOptional)	BaseModel
ConfigDictmodel_validatorc                   @   s   e Zd ZU dZdZeeeef  ed< dZ	ee
 ed< eed< dZeed< eegef ed< edd	Zed
dededefddZdedefddZdedeeef fddZdS )GraphQLAPIWrapperzWrapper around GraphQL API.

    To use, you should have the ``gql`` python package installed.
    This wrapper will use the GraphQL API to conduct queries.
    Ncustom_headersfetch_schema_from_transportgraphql_endpoint
gql_clientgql_functionforbid)extrabefore)modevaluesreturnc           
   
   C   s   zddl m}m } ddlm} W n ty# } ztd| d}~ww |d}||d |d}|d	d
}|||d}	|	|d< ||d< |S )z;Validate that the python package exists in the environment.r   )Clientgql)RequestsHTTPTransportz_Could not import gql python package. Try installing it with `pip install gql`. Received error: Nr
   r   )urlheadersr   T)	transportr   r   r   )r   r   gql.transport.requestsr   ImportErrorget)
clsr   r   r   r   er   r   r   client r!   a/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/graphql.pyvalidate_environment   s.   
z&GraphQLAPIWrapper.validate_environmentqueryc                 C   s   |  |}tj|ddS )z(Run a GraphQL query and get the results.   )indent)_execute_queryjsondumps)selfr$   resultr!   r!   r"   run1   s   
zGraphQLAPIWrapper.runc                 C   s   |  |}| j|}|S )z/Execute a GraphQL query and return the results.)r   r   execute)r*   r$   document_noder+   r!   r!   r"   r'   6   s   
z GraphQLAPIWrapper._execute_query)__name__
__module____qualname____doc__r
   r   r   str__annotations__r   boolr   r   r   r   model_configr   classmethodr#   r,   r'   r!   r!   r!   r"   r	      s   
 r	   )r(   typingr   r   r   r   pydanticr   r   r   r	   r!   r!   r!   r"   <module>   s    