Skip to content

Commit 316569b

Browse files
committed
Improved docs. Added schema page
1 parent d8eeb65 commit 316569b

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

docs/types/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Types Reference
1010
interfaces
1111
abstracttypes
1212
objecttypes
13+
schema
1314
mutations

docs/types/interfaces.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ An Interface contains the essential fields that will be implemented among
55
multiple ObjectTypes.
66

77
The basics:
8+
89
- Each Interface is a Python class that inherits from ``graphene.Interface``.
910
- Each attribute of the Interface represents a GraphQL field.
1011

docs/types/scalars.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ Scalars
22
=======
33

44
Graphene define the following base Scalar Types:
5+
56
- ``graphene.String``
67
- ``graphene.Int``
78
- ``graphene.Float``
89
- ``graphene.Boolean``
910
- ``graphene.ID``
1011

1112
Graphene also provides custom scalars for Dates and JSON:
13+
1214
- ``graphene.types.datetime.DateTime``
1315
- ``graphene.types.json.JSONString``
1416

docs/types/schema.rst

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Schema
2+
======
3+
4+
A Schema is created by supplying the root types of each type of operation, query and mutation (optional).
5+
A schema definition is then supplied to the validator and executor.
6+
7+
.. code:: python
8+
my_schema = Schema(
9+
query=MyRootQuery,
10+
mutation=MyRootMutation,
11+
)
12+
13+
Types
14+
-----
15+
16+
There are some cases where the schema could not access all the types that we plan to have.
17+
For example, when a field returns an ``Interface``, the schema doesn't know any of the
18+
implementations.
19+
20+
In this case, we would need to use the ``types`` argument when creating the Schema.
21+
22+
23+
.. code:: python
24+
25+
my_schema = Schema(
26+
query=MyRootQuery,
27+
types=[SomeExtraObjectType, ]
28+
)
29+
30+
31+
Querying
32+
--------
33+
34+
If you need to query a schema, you can directly call the ``execute`` method on it.
35+
36+
37+
.. code:: python
38+
39+
my_schema.execute('{ lastName }')
40+
41+
42+
Auto CamelCase field names
43+
--------------------------
44+
45+
By default all field and argument names (that are not
46+
explicitly set with the ``name`` arg) will be converted from
47+
`snake_case` to `camelCase` (`as the API is usually being consumed by a js/mobile client`)
48+
49+
So, for example if we have the following ObjectType
50+
51+
.. code:: python
52+
53+
class Person(graphene.ObjectType):
54+
last_name = graphene.String()
55+
other_name = graphene.String(name='_other_Name')
56+
57+
Then the ``last_name`` field name is converted to ``lastName``.
58+
59+
In the case we don't want to apply any transformation, we can specify
60+
the field name with the ``name`` argument. So ``other_name`` field name
61+
would be converted to ``_other_Name`` (without any other transformation).
62+
63+
So, you would need to query with:
64+
65+
.. code:: graphql
66+
67+
{
68+
lastName
69+
_other_Name
70+
}
71+
72+
73+
If you want to disable this behavior, you set use the ``auto_camelcase`` argument
74+
to ``False`` when you create the Schema.
75+
76+
.. code:: python
77+
78+
my_schema = Schema(
79+
query=MyRootQuery,
80+
auto_camelcase=False,
81+
)

0 commit comments

Comments
 (0)