11from graphene import ObjectType , String , Int , List , NonNull , Field
2- from graphene_federation import build_schema , extend , external , requires , key
2+ from graphene_federation import build_schema , extend , external , requires , key , provides
33
44
55@extend (fields = 'id' )
66class User (ObjectType ):
77 id = external (Int (required = True ))
88 primary_email = external (String ())
99 uppercase_email = requires (String (), fields = 'primaryEmail' )
10+ age = external (Int ())
1011
1112 def resolve_uppercase_email (self , info ):
1213 return self .primary_email .upper () if self .primary_email else self .primary_email
1314
15+ def resolve_age (self , info ):
16+ return 18
17+
1418
1519@key (fields = 'id' )
1620class Article (ObjectType ):
@@ -22,13 +26,32 @@ def __resolve_reference(self, info, **kwargs):
2226 return Article (id = self .id , text = f'text_{ self .id } ' )
2327
2428
29+ @provides
30+ class ArticleThatProvideAuthorAge (ObjectType ):
31+ """
32+ should not contain other graphene-federation decorators to proper test test-case
33+ """
34+ id = Int (required = True )
35+ text = String (required = True )
36+ author = provides (Field (User ), fields = 'age' )
37+
38+ def __resolve_reference (self , info , ** kwargs ):
39+ return Article (id = self .id , text = f'text_{ self .id } ' )
40+
41+
2542class Query (ObjectType ):
2643 articles = List (NonNull (lambda : Article ))
44+ articles_with_author_age_provide = List (NonNull (lambda : ArticleThatProvideAuthorAge ))
2745
2846 def resolve_articles (self , info ):
2947 return [
3048 Article (id = 1 , text = 'some text' , author = User (id = 5 ))
3149 ]
3250
51+ def resolve_articles_with_author_age_provide (self , info ):
52+ return [
53+ ArticleThatProvideAuthorAge (id = 1 , text = 'some text' , author = User (id = 5 ))
54+ ]
55+
3356
3457schema = build_schema (Query )
0 commit comments