
    Xj3                        d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZmZ d d	l m!Z! d d
l"m#Z# d dl$m%Z% d dl&m'Z' ddl(m)Z) er,d dl*m+Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl"m7Z7m8Z8  e# ede9      d      Z: G d de      Zdeee      deee      deee      deee      dee%   f
dZ;d ede<fd!Z=d"eed#d$d%f   de<fd&Z>dgZ?y')(    )defaultdict)cached_property)chain)TYPE_CHECKINGAnyDefaultDictDictIterableListMappingNewTypeOptionalSetTypeUnioncastStrawberryAnnotationprint_schema)Schema)StrawberryContainerStrawberryObjectDefinitionWithStrawberryObjectDefinitionget_object_definition)Info)scalar)StrawberryUnion)get_func_args   )#StrawberryFederationSchemaDirective)ExecutionContext)SchemaExtensionComposeDirective)StrawberryConfig)StrawberrySchemaDirective)EnumDefinition)ScalarDefinitionScalarWrapper_Anynamec                       e Zd Z	 	 	 	 	 	 	 	 	 	 	 d$dee   dee   dee   dee   dee   deeed   df      d	eed
      ded   deeeeeddf   f      dee   de	ddf fdZ
deee      deee      deee      deee      def
dZdedee   dee   fdZd%dZedee   fd       Zdddeeee   f   ddfdZ	 d&deee      ddfd Zded!   fd"Zd%d#Z xZS )'r   Nquerymutationsubscription
directivestypes
extensionsr#   execution_context_classGraphQLExecutionContextconfigr&   scalar_overridesr*   r)   schema_directivesenable_federation_2returnc                     | j                  ||||      }g |t        }t        |   |||||||||	|

       t	        |
      | _        |r"| j                         }| j                  |       y | j                          y )N)
r/   r0   r1   r2   r3   r4   r5   r7   r8   r9   )	_get_federation_query_typeFederationAnysuper__init__listr9   _add_compose_directives_add_link_directives_remove_resolvable_field)selfr/   r0   r1   r2   r3   r4   r5   r7   r8   r9   r:   composed_directives	__class__s                i/var/www/html/myl_app/scheduler-service/venv/lib/python3.12/site-packages/strawberry/federation/schema.pyr@   zSchema.__init__3   s    " //xuU'%''%!!$;-/ 	 	
 "&&7!8"&">">"@%%&9:))+    additional_typesc                     ddl ddlm} ddlm} j                  d       G  fdd             j                  d	      d
ffd       }|g}t        ||||      }	|	rVt        t        |	       j                  j                  d
<   j                  d j                        }
|j                  d|
        |d|      }||S  |d||f      }|j                  j                  rd|j                  _        |S )a  Returns a new query type that includes the _service field.

        If the query type is provided, it will be used as the base for the new
        query type. Otherwise, a new query type will be created.

        Federation needs the following two fields to be present in the query type:
        - _service: This field is used by the gateway to query for the capabilities
            of the federated service.
        - _entities: This field is used by the gateway to query for the entities
            that are part of the federated service.

        The _service field is added by default, but the _entities field is only
        added if the schema contains an entity type.
        r   N)create_type)merge_types_Servicer,   c                   F    e Zd ZU W j                   fd      Zeed<   y)2Schema._get_federation_query_type.<locals>.Servicec                      t               S Nr   rE   s   rH   <lambda>z;Schema._get_federation_query_type.<locals>.Service.<lambda>x   s    d!3 rI   )resolversdlN)__name__
__module____qualname__fieldrV   str__annotations__)rE   
strawberrys   rH   ServicerP   u   s"    !''3 ( C rI   r^   _servicer;   c                               S rR    )r^   s   rH   servicez2Schema._get_federation_query_type.<locals>.service{   s    9rI   	_entities)r-   rU   Query)r-   fieldsT)r]   strawberry.tools.create_typerL   strawberry.tools.merge_typesrM   typerZ   _get_entity_typer   r   entities_resolverr\   insert__strawberry_definition__extend)rE   r/   r0   r1   rJ   rL   rM   rb   re   entity_typeentities_fieldFederationQuery
query_typer^   r]   s   `            @@rH   r=   z!Schema._get_federation_query_type\   s   * 	<<	j	)	 	 
*	
 
		z		*	 	 
+	 &uhFVW?C%@D""228< (-- 4+A+A . N MM!^,%76B="" e$

 **11:>J007rI   inforepresentationsc                 j   g }|D ]  }|j                  d      }| j                  j                  |   }t        t        |j
                        }t        |j                  d      r6|j                  j                  }t        |      }	|}
d|	v r||
d<   	  |di |
}nSddlm} |j                  j                  }|j                  j                  j                  }	  |||j                  ||      }|j#                  |        |S # t        $ r}|}Y d }~%d }~ww xY w# t        $ r t!        d|       }Y Fw xY w)	N
__typenameresolve_referencerr   r   )convert_argument)type_scalar_registryr7   z Unable to resolve reference for ra   )popschema_convertertype_mapr   r   
definitionhasattroriginrv   r   	Exceptionstrawberry.types.argumentsrw   schemar7   ry   	TypeErrorappend)rE   rr   rs   resultsrepresentation	type_namerx   r}   rv   	func_argskwargsresulterw   r7   ry   s                   rH   rj   zSchema.entities_resolver   sG    - $	#N&**<8I))229=E8%:J:JKJz((*=>$.$5$5$G$G!)*;<	' Y&%)F6N.88F H++"&++">">"N"NW-&(//(7%	F NN6"I$	#L ) ! F ! W&)I)'UVFWs*   D D 	D	DDD21D2c                 f    ddl m} ddlm} | j                  D ]  }t        ||      s||_         y )Nr   )UNSETr    Key)strawberry.types.unsetr   r9   r   schema_directives_in_use
isinstance
resolvable)rE   r   r   	directives       rH   rD   zSchema._remove_resolvable_field   s1     	1*66 	-I)S)',	$	-rI   c                 ^   | j                   j                  j                         }g }|D ]  }|j                  j	                  d      }|s!|j                  |j                         t        |dg       }t        |dg       }t        ||      D ]  }|j                  |j                           |S )Nzstrawberry-definitionre   values)	_schemar|   r   r4   getrm   r2   getattrr   )rE   all_graphql_typesr2   rx   strawberry_definitionre   r   rZ   s           rH   r   zSchema.schema_directives_in_use   s     LL1188:#%
& 	4E$)$4$4$8$89P$Q!(3>>?2HbAF2HbAFvv. 4!!%"2"234	4 rI   r   r'   directive_by_urlc                     t        |t              sy |j                  sy |j                  j                  }| j                  j
                  j                  |      }|d| d}||   j                  d|        y )Nz$https://directives.strawberry.rocks/z/v0.1@)r   r!   compose_options
import_urlr7   name_converterfrom_directiveadd)rE   r   r   r   r-   s        rH    _add_link_for_composed_directivez'Schema._add_link_for_composed_directive   sx    
 )%HI((..99
{{))88C
 ?vUKJ$((1TF4rI   additional_directivesc                    ddl m}m} t        t              }|xs g }| j
                  |z   D ]l  }|j                  }| j                  ||       t        ||      s.||j                  j                     j                  d|j                  j                          n |j                         D cg c]!  \  }} ||t        t        |                  # }	}}| j                   |	z   | _         y c c}}w )Nr    )FederationDirectiveLinkr   )urlimport_)r9   r   r   r   setr   __strawberry_directive__r   r   imported_fromr   r   r-   itemsrA   sorted)
rE   r   r   r   r   r   r}   r   r2   link_directivess
             rH   rC   zSchema._add_link_directives  s     	A7B37G 5 ;669NN 	I";;J11*>NO)%89 !8!8!<!<=AA	//4456	 $4#9#9#;)

  Z	 VJ/0)
 )
 "&!7!7/!I)
s   /&C-r%   c                 8   ddl m} g }| j                  D ]n  }|j                  }t	        |t
              }|s"|j                  s/| j                  j                  j                  |      }|j                   |d|              p | j                   |z   | _         |S )Nr    r$   r   r,   )r9   r%   r   r   r   r!   r   r7   r   r   r   )rE   r%   compose_directivesr   r}   is_federation_schema_directiver-   s          rH   rB   zSchema._add_compose_directives  s    75766 	I";;J-7?.* .*2L2L{{11@@L"))$ Z	  "&!7!7:L!L!!rI   c                      y rR   ra   rS   s    rH   _warn_for_federation_directivesz&Schema._warn_for_federation_directives8  s    
 	rI   )NNNra   ra   ra   NNNra   F)r;   NrR   )rW   rX   rY   r   r   r
   r   r	   objectboolr@   r   r=   r   r   r>   rj   rD   r   r   r   r[   r   r   rC   rB   r   __classcell__)rG   s   @rH   r   r   2   s#    !%#''+%' "RTMQ/3 .0$)',~', 4.', tn	', TN', ~', U4(9#:<M#MNO', "*$/H*I!J', +,', #t_6HHIIJ
', $F+', "',  
!',R@;<=@ 4 >?@@ t$BCD	@
 #4(F#GH@ 
@D+++/+>+	m	+Z	- $v,  *5.5 "#s3x-05 
	5. ?CJ%-d6l%;J	J:".@)A "2rI   r   r/   r0   r1   rJ   r;   c                 R   t               }| ||g|}t               }|r|j                         }|t        |t              r|j                  }t        |t              rt        |d      }|R|j                  rt        |      r|j                  |       |j                  D ]S  }	|	j                  r|	j                  |v r|j                  |	j                         |j                  |	j                         U |r|sy t        |d       }
t        dt        d |
D                    S )NF)strictc                 .    | j                   j                  S rR   )rl   r-   )ts    rH   rT   z"_get_entity_type.<locals>.<lambda>l  s    a6Q6Q6V6V rI   )key_Entityc              3   2   K   | ]  }t        |        y wrR   r   ).0rx   s     rH   	<genexpr>z#_get_entity_type.<locals>.<genexpr>p  s     Uu3E:U   )type_annotations)r   rz   r   r   of_typer   is_object_type_has_federation_keysr   re   rh   r   r   r   tuple)r/   r0   r1   rJ   entity_typesstackseenrx   type_definitionrZ   sorted_typess              rH   ri   ri   @  s    5L xI8HIE5D
		= 34MME  34 0eD")).B?.SU#$++ 	%EzzejjD0HHUZZ LL$	%# 0 ,,VWLUUU rI   r   c                 &    ddl m} t        | |      S )Nr    r   )r9   r   r   )r   r   s     rH   _is_keyr   t  s    &i%%rI   r}   r)   r(   r   c                 d    t        | t              r t        d | j                  xs g D              S y)Nc              3   2   K   | ]  }t        |        y wrR   )r   )r   r   s     rH   r   z'_has_federation_keys.<locals>.<genexpr>  s     S)79%Sr   F)r   r   anyr2   )r}   s    rH   r   r   z  s/     *89Sz7L7L7RPRSSSrI   N)@collectionsr   	functoolsr   	itertoolsr   typingr   r   r   r	   r
   r   r   r   r   r   r   r   r   strawberry.annotationr   strawberry.printerr   strawberry.schemar   
BaseSchemastrawberry.types.baser   r   r   r   strawberry.types.infor   strawberry.types.scalarr   strawberry.types.unionr   strawberry.utils.inspectr   schema_directiver!   graphqlr"   r6   strawberry.extensionsr#   'strawberry.federation.schema_directivesr%   strawberry.schema.configr&   strawberry.schema_directiver'   strawberry.types.enumr(   r)   r*   r   r>   ri   r   r   r   __all__ra   rI   rH   <module>r      s2   # %      7 + 2  ' * 2 2 AC5H9E4G wvv.V<KZ K\1D7891t:;<1 4 >?@1 t$BCD	1
 o1h&s &t &"	 
 *rI   