@@ -114,6 +114,33 @@ class Meta:
114114 assert isinstance (Article ._meta , ArticleTypeOptions )
115115
116116
117+ def test_django_objecttype_with_custom_meta_fields ():
118+ class ArticleTypeOptions (DjangoObjectTypeOptions ):
119+ """Article Type Options with extra fields"""
120+
121+ fields = {"headline_with_lang" : String ()}
122+
123+ class ArticleType (DjangoObjectType ):
124+ class Meta :
125+ abstract = True
126+
127+ @classmethod
128+ def __init_subclass_with_meta__ (cls , ** options ):
129+ options .setdefault ("_meta" , ArticleTypeOptions (cls ))
130+ super (ArticleType , cls ).__init_subclass_with_meta__ (** options )
131+
132+ class Article (ArticleType ):
133+ class Meta :
134+ model = ArticleModel
135+ fields = "__all__"
136+
137+ headline_with_lang_field = Article ._meta .fields .get ("headline_with_lang" )
138+
139+ assert isinstance (Article ._meta , ArticleTypeOptions )
140+ assert headline_with_lang_field is not None
141+ assert isinstance (headline_with_lang_field , String )
142+
143+
117144def test_schema_representation ():
118145 expected = dedent (
119146 """\
@@ -278,6 +305,81 @@ class Meta:
278305 assert fields == ["id" , "email" , "films" ]
279306
280307
308+ @with_local_registry
309+ def test_django_objecttype_fields_custom_meta_fields ():
310+ class ArticleTypeOptions (DjangoObjectTypeOptions ):
311+ """Article Type Options with extra fields"""
312+
313+ fields = {"headline_with_lang" : String ()}
314+
315+ class ArticleType (DjangoObjectType ):
316+ class Meta :
317+ abstract = True
318+
319+ @classmethod
320+ def __init_subclass_with_meta__ (cls , ** options ):
321+ options .setdefault ("_meta" , ArticleTypeOptions (cls ))
322+ super (ArticleType , cls ).__init_subclass_with_meta__ (** options )
323+
324+ class Article (ArticleType ):
325+ class Meta :
326+ model = ArticleModel
327+ fields = ("editor" , "lang" , "importance" )
328+
329+ fields = list (Article ._meta .fields .keys ())
330+ assert fields == ["editor" , "lang" , "importance" ]
331+
332+
333+ @with_local_registry
334+ def test_django_objecttype_fields_custom_meta_fields_include ():
335+ class ArticleTypeOptions (DjangoObjectTypeOptions ):
336+ """Article Type Options with extra fields"""
337+
338+ fields = {"headline_with_lang" : String ()}
339+
340+ class ArticleType (DjangoObjectType ):
341+ class Meta :
342+ abstract = True
343+
344+ @classmethod
345+ def __init_subclass_with_meta__ (cls , ** options ):
346+ options .setdefault ("_meta" , ArticleTypeOptions (cls ))
347+ super (ArticleType , cls ).__init_subclass_with_meta__ (** options )
348+
349+ class Article (ArticleType ):
350+ class Meta :
351+ model = ArticleModel
352+ fields = ("headline_with_lang" , "editor" , "lang" , "importance" )
353+
354+ fields = list (Article ._meta .fields .keys ())
355+ assert fields == ["headline_with_lang" , "editor" , "lang" , "importance" ]
356+
357+
358+ @with_local_registry
359+ def test_django_objecttype_fields_custom_meta_fields_all ():
360+ class ArticleTypeOptions (DjangoObjectTypeOptions ):
361+ """Article Type Options with extra fields"""
362+
363+ fields = {"headline_with_lang" : String ()}
364+
365+ class ArticleType (DjangoObjectType ):
366+ class Meta :
367+ abstract = True
368+
369+ @classmethod
370+ def __init_subclass_with_meta__ (cls , ** options ):
371+ options .setdefault ("_meta" , ArticleTypeOptions (cls ))
372+ super (ArticleType , cls ).__init_subclass_with_meta__ (** options )
373+
374+ class Article (ArticleType ):
375+ class Meta :
376+ model = ArticleModel
377+ fields = "__all__"
378+
379+ fields = list (Article ._meta .fields .keys ())
380+ assert len (fields ) == len (ArticleModel ._meta .get_fields ()) + 1
381+
382+
281383@with_local_registry
282384def test_django_objecttype_fields ():
283385 class Reporter (DjangoObjectType ):
0 commit comments