Skip to content

Commit 19f7769

Browse files
committed
Added registry docs
1 parent d81892e commit 19f7769

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/registry.rst

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Graphene-Django Registry
2+
========================
3+
4+
Graphene-Django uses a Registry to keep track of all the Django Models
5+
and the ``DjangoObjectTypes`` associated to them.
6+
7+
This way, we make the library smart enough to convert automatically the
8+
relations between models to Graphene fields automatically (when possible).
9+
10+
11+
get_global_registry
12+
-------------------
13+
14+
By default, all model/objecttype relations will live in the global registry.
15+
16+
.. code:: python
17+
18+
from graphene_django.registry get_global_registry
19+
20+
class Reporter(DjangoObjectType):
21+
'''Reporter description'''
22+
class Meta:
23+
model = ReporterModel
24+
25+
global_registry = get_global_registry
26+
global_registry.get_type_for_model(ReporterModel) # == Reporter
27+
28+
29+
One Model, multiple types
30+
-------------------------
31+
32+
There will be some cases where we need one Django Model to
33+
have multiple graphene ``ObjectType``s associated to it.
34+
35+
.. code:: python
36+
37+
from graphene_django.registry import Registry
38+
39+
class Reporter(DjangoObjectType):
40+
'''Reporter description'''
41+
class Meta:
42+
model = ReporterModel
43+
44+
class Reporter2(DjangoObjectType):
45+
'''Reporter2 description'''
46+
class Meta:
47+
model = ReporterModel
48+
skip_global_registry = True
49+
# We can also specify a custom registry with
50+
# registry = Registry()
51+
52+
This way, the ``ReporterModel`` could have two different types living in the same
53+
schema.

0 commit comments

Comments
 (0)