|
| 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