Skip to content

Commit dda294d

Browse files
authored
Merge branch 'master' into master
2 parents 71b4de9 + edd090e commit dda294d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1187
-183
lines changed

.travis.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ python:
66
- 3.5
77
- pypy
88
before_install:
9-
- |
10-
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
11-
export PYENV_ROOT="$HOME/.pyenv"
12-
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
13-
cd "$PYENV_ROOT" && git pull
14-
else
15-
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
16-
fi
17-
export PYPY_VERSION="4.0.1"
18-
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
19-
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
20-
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
21-
fi
9+
- |
10+
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
11+
export PYENV_ROOT="$HOME/.pyenv"
12+
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
13+
cd "$PYENV_ROOT" && git pull
14+
else
15+
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
16+
fi
17+
export PYPY_VERSION="4.0.1"
18+
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
19+
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
20+
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
21+
fi
2222
install:
2323
- |
2424
if [ "$TEST_TYPE" = build ]; then
@@ -52,3 +52,10 @@ matrix:
5252
include:
5353
- python: '2.7'
5454
env: TEST_TYPE=lint
55+
deploy:
56+
provider: pypi
57+
user: syrusakbary
58+
on:
59+
tags: true
60+
password:
61+
secure: LHOp9DvYR+70vj4YVY8+JRNCKUOfYZREEUY3+4lMUpY7Zy5QwDfgEMXG64ybREH9dFldpUqVXRj53eeU3spfudSfh8NHkgqW7qihez2AhSnRc4dK6ooNfB+kLcSoJ4nUFGxdYImABc4V1hJvflGaUkTwDNYVxJF938bPaO797IvSbuI86llwqkvuK2Vegv9q/fy9sVGaF9VZIs4JgXwR5AyDR7FBArl+S84vWww4vTFD33hoE88VR4QvFY3/71BwRtQrnCMm7AOm31P9u29yi3bpzQpiOR2rHsgrsYdm597QzFKVxYwsmf9uAx2bpbSPy2WibunLePIvOFwm8xcfwnz4/J4ONBc5PSFmUytTWpzEnxb0bfUNLuYloIS24V6OZ8BfAhiYZ1AwySeJCQDM4Vk1V8IF6trTtyx5EW/uV9jsHCZ3LFsAD7UnFRTosIgN3SAK3ZWCEk5oF2IvjecsolEfkRXB3q9EjMkkuXRUeFDH2lWJLgNE27BzY6myvZVzPmfwZUsPBlPD/6w+WLSp97Rjgr9zS3T1d4ddqFM4ZYu04f2i7a/UUQqG+itzzuX5DWLPvzuNt37JB45mB9IsvxPyXZ6SkAcLl48NGyKok1f3vQnvphkfkl4lni29woKhaau8xlsuEDrcwOoeAsVcZXiItg+l+z2SlIwM0A06EvQ=

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,21 @@ After developing, the full test suite can be evaluated by running:
8383
```sh
8484
python setup.py test # Use --pytest-args="-v -s" for verbose mode
8585
```
86+
87+
88+
### Documentation
89+
90+
The documentation is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
91+
92+
The documentation dependencies are installed by running:
93+
94+
```sh
95+
cd docs
96+
pip install -r requirements.txt
97+
```
98+
99+
Then to produce a HTML version of the documentation:
100+
101+
```sh
102+
make html
103+
```

README.rst

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
Please read `UPGRADE-v1.0.md`_ to learn how to upgrade to Graphene ``1.0``.
1+
Please read `UPGRADE-v1.0.md </UPGRADE-v1.0.md>`__ to learn how to
2+
upgrade to Graphene ``1.0``.
23

34
--------------
45

5-
|Graphene Logo| `Graphene`_ |Build Status| |PyPI version| |Coverage Status|
6-
===========================================================================
6+
|Graphene Logo| `Graphene <http://graphene-python.org>`__ |Build Status| |PyPI version| |Coverage Status|
7+
=========================================================================================================
78

8-
`Graphene`_ is a Python library for building GraphQL schemas/types fast
9-
and easily.
9+
`Graphene <http://graphene-python.org>`__ is a Python library for
10+
building GraphQL schemas/types fast and easily.
1011

1112
- **Easy to use:** Graphene helps you use GraphQL in Python without
1213
effort.
1314
- **Relay:** Graphene has builtin support for Relay
1415
- **Data agnostic:** Graphene supports any kind of data source: SQL
15-
(Django, SQLAlchemy), NoSQL, custom Python objects, etc. We believe that
16-
by providing a complete API you could plug Graphene anywhere your
17-
data lives and make your data available through GraphQL.
16+
(Django, SQLAlchemy), NoSQL, custom Python objects, etc. We believe
17+
that by providing a complete API you could plug Graphene anywhere
18+
your data lives and make your data available through GraphQL.
1819

1920
Integrations
2021
------------
2122

2223
Graphene has multiple integrations with different frameworks:
2324

24-
+---------------------+-------------------------------------+
25-
| integration | Package |
26-
+=====================+=====================================+
27-
| Django | `graphene-django`_ |
28-
+---------------------+-------------------------------------+
29-
| SQLAlchemy | `graphene-sqlalchemy`_ |
30-
+---------------------+-------------------------------------+
31-
| Google App Engine | `graphene-gae`_ |
32-
+---------------------+-------------------------------------+
33-
| Peewee | *In progress* (`Tracking Issue`_) |
34-
+---------------------+-------------------------------------+
25+
+---------------------+----------------------------------------------------------------------------------------------+
26+
| integration | Package |
27+
+=====================+==============================================================================================+
28+
| Django | `graphene-django <https://github.com/graphql-python/graphene-django/>`__ |
29+
+---------------------+----------------------------------------------------------------------------------------------+
30+
| SQLAlchemy | `graphene-sqlalchemy <https://github.com/graphql-python/graphene-sqlalchemy/>`__ |
31+
+---------------------+----------------------------------------------------------------------------------------------+
32+
| Google App Engine | `graphene-gae <https://github.com/graphql-python/graphene-gae/>`__ |
33+
+---------------------+----------------------------------------------------------------------------------------------+
34+
| Peewee | *In progress* (`Tracking Issue <https://github.com/graphql-python/graphene/issues/289>`__) |
35+
+---------------------+----------------------------------------------------------------------------------------------+
3536

3637
Installation
3738
------------
@@ -45,7 +46,8 @@ For instaling graphene, just run this command in your shell
4546
1.0 Upgrade Guide
4647
-----------------
4748

48-
Please read `UPGRADE-v1.0.md`_ to learn how to upgrade.
49+
Please read `UPGRADE-v1.0.md </UPGRADE-v1.0.md>`__ to learn how to
50+
upgrade.
4951

5052
Examples
5153
--------
@@ -74,10 +76,11 @@ Then Querying ``graphene.Schema`` is as simple as:
7476
result = schema.execute(query)
7577
7678
If you want to learn even more, you can also check the following
77-
`examples`_:
79+
`examples <examples/>`__:
7880

79-
- **Basic Schema**: `Starwars example`_
80-
- **Relay Schema**: `Starwars Relay example`_
81+
- **Basic Schema**: `Starwars example <examples/starwars>`__
82+
- **Relay Schema**: `Starwars Relay
83+
example <examples/starwars_relay>`__
8184

8285
Contributing
8386
------------
@@ -94,15 +97,24 @@ After developing, the full test suite can be evaluated by running:
9497
9598
python setup.py test # Use --pytest-args="-v -s" for verbose mode
9699
97-
.. _UPGRADE-v1.0.md: /UPGRADE-v1.0.md
98-
.. _Graphene: http://graphene-python.org
99-
.. _graphene-django: https://github.com/graphql-python/graphene-django/
100-
.. _graphene-sqlalchemy: https://github.com/graphql-python/graphene-sqlalchemy/
101-
.. _graphene-gae: https://github.com/graphql-python/graphene-gae/
102-
.. _Tracking Issue: https://github.com/graphql-python/graphene/issues/289
103-
.. _examples: examples/
104-
.. _Starwars example: examples/starwars
105-
.. _Starwars Relay example: examples/starwars_relay
100+
Documentation
101+
~~~~~~~~~~~~~
102+
103+
The documentation is generated using the excellent
104+
`Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme.
105+
106+
The documentation dependencies are installed by running:
107+
108+
.. code:: sh
109+
110+
cd docs
111+
pip install -r requirements.txt
112+
113+
Then to produce a HTML version of the documentation:
114+
115+
.. code:: sh
116+
117+
make html
106118
107119
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
108120
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master

docs/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@ dummy:
223223
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
224224
@echo
225225
@echo "Build finished. Dummy builder generates no files."
226+
227+
.PHONY: livehtml
228+
livehtml:
229+
sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html

docs/execution/index.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=========
2+
Execution
3+
=========
4+
5+
For executing a query a schema, you can directly call the ``execute`` method on it.
6+
7+
8+
.. code:: python
9+
10+
schema = graphene.Schema(...)
11+
result = schema.execute('{ name }')
12+
13+
``result`` represents he result of execution. ``result.data`` is the result of executing the query, ``result.errors`` is ``None`` if no errors occurred, and is a non-empty list if an error occurred.
14+
15+
16+
Context
17+
_______
18+
19+
You can pass context to a query via ``context_value``.
20+
21+
22+
.. code:: python
23+
24+
class Query(graphene.ObjectType):
25+
name = graphene.String()
26+
27+
def resolve_name(self, args, context, info):
28+
return context.get('name')
29+
30+
schema = graphene.Schema(Query)
31+
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
32+
33+
34+
Middleware
35+
__________
36+
37+
.. toctree::
38+
:maxdepth: 1
39+
40+
middleware

docs/execution/middleware.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Middleware
2+
==========
3+
4+
You can use ``middleware`` to affect the evaluation of fields in your schema.
5+
6+
A middleware is any object that responds to ``resolve(*args, next_middleware)``.
7+
8+
Inside that method, it should either:
9+
10+
- Send ``resolve`` to the next middleware to continue the evaluation; or
11+
- Return a value to end the evaluation early.
12+
13+
14+
Resolve arguments
15+
-----------------
16+
17+
Middlewares ``resolve`` is invoked with several arguments:
18+
19+
- ``next`` represents the execution chain. Call ``next`` to continue evalution.
20+
- ``root`` is the root value object passed throughout the query.
21+
- ``args`` is the hash of arguments passed to the field.
22+
- ``context`` is the context object passed throughout the query.
23+
- ``info`` is the resolver info.
24+
25+
26+
Example
27+
-------
28+
29+
This middleware only continues evaluation if the ``field_name`` is not ``'user'``
30+
31+
.. code:: python
32+
33+
class AuthorizationMiddleware(object):
34+
def resolve(self, next, root, args, context, info):
35+
if info.field_name == 'user':
36+
return None
37+
return next(root, args, context, info)
38+
39+
40+
And then execute it with:
41+
42+
.. code:: python
43+
44+
result = schema.execute('THE QUERY', middleware=[AuthorizationMiddleware()])

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Contents:
88

99
quickstart
1010
types/index
11+
execution/index
1112
relay/index
1213

1314
Integrations

docs/quickstart.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Getting started
22
===============
33

4+
What is GraphQL?
5+
----------------
6+
7+
For an introduction to GraphQL and an overview of its concepts, please refer
8+
to `the official introduction <http://graphql.org/learn/>`.
9+
410
Let’s build a basic GraphQL schema from scratch.
511

612
Requirements

docs/types/interfaces.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ and ``Droid`` are two implementations of that interface.
2323
name = graphene.String()
2424
2525
# Human is a Character implementation
26-
class Human(ObjectType):
26+
class Human(graphene.ObjectType):
2727
class Meta:
2828
interfaces = (Character, )
2929
3030
born_in = graphene.String()
3131
3232
# Droid is a Character implementation
33-
class Droid(Character):
33+
class Droid(graphene.ObjectType):
3434
class Meta:
3535
interfaces = (Character, )
3636

docs/types/mutations.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,69 @@ We should receive:
7676
"ok": true
7777
}
7878
}
79+
80+
InputFields and InputObjectTypes
81+
----------------------
82+
InputFields are used in mutations to allow nested input data for mutations
83+
84+
To use an InputField you define an InputObjectType that specifies the structure of your input data
85+
86+
87+
88+
89+
.. code:: python
90+
91+
import graphene
92+
93+
class PersonInput(graphene.InputObjectType):
94+
name = graphene.String()
95+
age = graphene.Int()
96+
97+
class CreatePerson(graphene.Mutation):
98+
class Input:
99+
person_data = graphene.InputField(PersonInput)
100+
101+
person = graphene.Field(lambda: Person)
102+
103+
def mutate(self, args, context, info):
104+
p_data = args.get('person_data')
105+
106+
name = p_data.get('name')
107+
age = p_data.get('age')
108+
109+
person = Person(name=name, age=age)
110+
return CreatePerson(person=person)
111+
112+
113+
Note that **name** and **age** are part of **person_data** now
114+
115+
Using the above mutation your new query would look like this:
116+
117+
.. code:: graphql
118+
119+
mutation myFirstMutation {
120+
createPerson(personData: {name:"Peter", age: 24}) {
121+
person {
122+
name,
123+
age
124+
}
125+
}
126+
}
127+
128+
InputObjectTypes can also be fields of InputObjectTypes allowing you to have
129+
as complex of input data as you need
130+
131+
.. code:: python
132+
133+
import graphene
134+
135+
class LatLngInput(graphene.InputObjectType):
136+
lat = graphene.Float()
137+
lng = graphene.Float()
138+
139+
#A location has a latlng associated to it
140+
class LocationInput(graphene.InputObjectType):
141+
name = graphene.String()
142+
latlng = graphene.InputField(LatLngInputType)
143+
144+

0 commit comments

Comments
 (0)