Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Dec 18, 2016
2 parents 71b4de9 + edd090e commit dda294d
Show file tree
Hide file tree
Showing 57 changed files with 1,187 additions and 183 deletions.
33 changes: 20 additions & 13 deletions .travis.yml
Expand Up @@ -6,19 +6,19 @@ python:
- 3.5
- pypy
before_install:
- |
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
export PYENV_ROOT="$HOME/.pyenv"
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
cd "$PYENV_ROOT" && git pull
else
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi
export PYPY_VERSION="4.0.1"
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
fi
- |
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
export PYENV_ROOT="$HOME/.pyenv"
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
cd "$PYENV_ROOT" && git pull
else
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
fi
export PYPY_VERSION="4.0.1"
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
fi
install:
- |
if [ "$TEST_TYPE" = build ]; then
Expand Down Expand Up @@ -52,3 +52,10 @@ matrix:
include:
- python: '2.7'
env: TEST_TYPE=lint
deploy:
provider: pypi
user: syrusakbary
on:
tags: true
password:
secure: LHOp9DvYR+70vj4YVY8+JRNCKUOfYZREEUY3+4lMUpY7Zy5QwDfgEMXG64ybREH9dFldpUqVXRj53eeU3spfudSfh8NHkgqW7qihez2AhSnRc4dK6ooNfB+kLcSoJ4nUFGxdYImABc4V1hJvflGaUkTwDNYVxJF938bPaO797IvSbuI86llwqkvuK2Vegv9q/fy9sVGaF9VZIs4JgXwR5AyDR7FBArl+S84vWww4vTFD33hoE88VR4QvFY3/71BwRtQrnCMm7AOm31P9u29yi3bpzQpiOR2rHsgrsYdm597QzFKVxYwsmf9uAx2bpbSPy2WibunLePIvOFwm8xcfwnz4/J4ONBc5PSFmUytTWpzEnxb0bfUNLuYloIS24V6OZ8BfAhiYZ1AwySeJCQDM4Vk1V8IF6trTtyx5EW/uV9jsHCZ3LFsAD7UnFRTosIgN3SAK3ZWCEk5oF2IvjecsolEfkRXB3q9EjMkkuXRUeFDH2lWJLgNE27BzY6myvZVzPmfwZUsPBlPD/6w+WLSp97Rjgr9zS3T1d4ddqFM4ZYu04f2i7a/UUQqG+itzzuX5DWLPvzuNt37JB45mB9IsvxPyXZ6SkAcLl48NGyKok1f3vQnvphkfkl4lni29woKhaau8xlsuEDrcwOoeAsVcZXiItg+l+z2SlIwM0A06EvQ=
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -83,3 +83,21 @@ After developing, the full test suite can be evaluated by running:
```sh
python setup.py test # Use --pytest-args="-v -s" for verbose mode
```


### Documentation

The documentation is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.

The documentation dependencies are installed by running:

```sh
cd docs
pip install -r requirements.txt
```

Then to produce a HTML version of the documentation:

```sh
make html
```
76 changes: 44 additions & 32 deletions README.rst
@@ -1,37 +1,38 @@
Please read `UPGRADE-v1.0.md`_ to learn how to upgrade to Graphene ``1.0``.
Please read `UPGRADE-v1.0.md </UPGRADE-v1.0.md>`__ to learn how to
upgrade to Graphene ``1.0``.

--------------

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

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

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

Integrations
------------

Graphene has multiple integrations with different frameworks:

+---------------------+-------------------------------------+
| integration | Package |
+=====================+=====================================+
| Django | `graphene-django`_ |
+---------------------+-------------------------------------+
| SQLAlchemy | `graphene-sqlalchemy`_ |
+---------------------+-------------------------------------+
| Google App Engine | `graphene-gae`_ |
+---------------------+-------------------------------------+
| Peewee | *In progress* (`Tracking Issue`_) |
+---------------------+-------------------------------------+
+---------------------+----------------------------------------------------------------------------------------------+
| integration | Package |
+=====================+==============================================================================================+
| Django | `graphene-django <https://github.com/graphql-python/graphene-django/>`__ |
+---------------------+----------------------------------------------------------------------------------------------+
| SQLAlchemy | `graphene-sqlalchemy <https://github.com/graphql-python/graphene-sqlalchemy/>`__ |
+---------------------+----------------------------------------------------------------------------------------------+
| Google App Engine | `graphene-gae <https://github.com/graphql-python/graphene-gae/>`__ |
+---------------------+----------------------------------------------------------------------------------------------+
| Peewee | *In progress* (`Tracking Issue <https://github.com/graphql-python/graphene/issues/289>`__) |
+---------------------+----------------------------------------------------------------------------------------------+

Installation
------------
Expand All @@ -45,7 +46,8 @@ For instaling graphene, just run this command in your shell
1.0 Upgrade Guide
-----------------

Please read `UPGRADE-v1.0.md`_ to learn how to upgrade.
Please read `UPGRADE-v1.0.md </UPGRADE-v1.0.md>`__ to learn how to
upgrade.

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

- **Basic Schema**: `Starwars example`_
- **Relay Schema**: `Starwars Relay example`_
- **Basic Schema**: `Starwars example <examples/starwars>`__
- **Relay Schema**: `Starwars Relay
example <examples/starwars_relay>`__

Contributing
------------
Expand All @@ -94,15 +97,24 @@ After developing, the full test suite can be evaluated by running:
python setup.py test # Use --pytest-args="-v -s" for verbose mode
.. _UPGRADE-v1.0.md: /UPGRADE-v1.0.md
.. _Graphene: http://graphene-python.org
.. _graphene-django: https://github.com/graphql-python/graphene-django/
.. _graphene-sqlalchemy: https://github.com/graphql-python/graphene-sqlalchemy/
.. _graphene-gae: https://github.com/graphql-python/graphene-gae/
.. _Tracking Issue: https://github.com/graphql-python/graphene/issues/289
.. _examples: examples/
.. _Starwars example: examples/starwars
.. _Starwars Relay example: examples/starwars_relay
Documentation
~~~~~~~~~~~~~

The documentation is generated using the excellent
`Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme.

The documentation dependencies are installed by running:

.. code:: sh
cd docs
pip install -r requirements.txt
Then to produce a HTML version of the documentation:

.. code:: sh
make html
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master
Expand Down
4 changes: 4 additions & 0 deletions docs/Makefile
Expand Up @@ -223,3 +223,7 @@ dummy:
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
@echo
@echo "Build finished. Dummy builder generates no files."

.PHONY: livehtml
livehtml:
sphinx-autobuild -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
40 changes: 40 additions & 0 deletions docs/execution/index.rst
@@ -0,0 +1,40 @@
=========
Execution
=========

For executing a query a schema, you can directly call the ``execute`` method on it.


.. code:: python
schema = graphene.Schema(...)
result = schema.execute('{ name }')
``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.


Context
_______

You can pass context to a query via ``context_value``.


.. code:: python
class Query(graphene.ObjectType):
name = graphene.String()
def resolve_name(self, args, context, info):
return context.get('name')
schema = graphene.Schema(Query)
result = schema.execute('{ name }', context_value={'name': 'Syrus'})
Middleware
__________

.. toctree::
:maxdepth: 1

middleware
44 changes: 44 additions & 0 deletions docs/execution/middleware.rst
@@ -0,0 +1,44 @@
Middleware
==========

You can use ``middleware`` to affect the evaluation of fields in your schema.

A middleware is any object that responds to ``resolve(*args, next_middleware)``.

Inside that method, it should either:

- Send ``resolve`` to the next middleware to continue the evaluation; or
- Return a value to end the evaluation early.


Resolve arguments
-----------------

Middlewares ``resolve`` is invoked with several arguments:

- ``next`` represents the execution chain. Call ``next`` to continue evalution.
- ``root`` is the root value object passed throughout the query.
- ``args`` is the hash of arguments passed to the field.
- ``context`` is the context object passed throughout the query.
- ``info`` is the resolver info.


Example
-------

This middleware only continues evaluation if the ``field_name`` is not ``'user'``

.. code:: python
class AuthorizationMiddleware(object):
def resolve(self, next, root, args, context, info):
if info.field_name == 'user':
return None
return next(root, args, context, info)
And then execute it with:

.. code:: python
result = schema.execute('THE QUERY', middleware=[AuthorizationMiddleware()])
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -8,6 +8,7 @@ Contents:

quickstart
types/index
execution/index
relay/index

Integrations
Expand Down
6 changes: 6 additions & 0 deletions docs/quickstart.rst
@@ -1,6 +1,12 @@
Getting started
===============

What is GraphQL?
----------------

For an introduction to GraphQL and an overview of its concepts, please refer
to `the official introduction <http://graphql.org/learn/>`.

Let’s build a basic GraphQL schema from scratch.

Requirements
Expand Down
4 changes: 2 additions & 2 deletions docs/types/interfaces.rst
Expand Up @@ -23,14 +23,14 @@ and ``Droid`` are two implementations of that interface.
name = graphene.String()
# Human is a Character implementation
class Human(ObjectType):
class Human(graphene.ObjectType):
class Meta:
interfaces = (Character, )
born_in = graphene.String()
# Droid is a Character implementation
class Droid(Character):
class Droid(graphene.ObjectType):
class Meta:
interfaces = (Character, )
Expand Down
66 changes: 66 additions & 0 deletions docs/types/mutations.rst
Expand Up @@ -76,3 +76,69 @@ We should receive:
"ok": true
}
}
InputFields and InputObjectTypes
----------------------
InputFields are used in mutations to allow nested input data for mutations

To use an InputField you define an InputObjectType that specifies the structure of your input data




.. code:: python
import graphene
class PersonInput(graphene.InputObjectType):
name = graphene.String()
age = graphene.Int()
class CreatePerson(graphene.Mutation):
class Input:
person_data = graphene.InputField(PersonInput)
person = graphene.Field(lambda: Person)
def mutate(self, args, context, info):
p_data = args.get('person_data')
name = p_data.get('name')
age = p_data.get('age')
person = Person(name=name, age=age)
return CreatePerson(person=person)
Note that **name** and **age** are part of **person_data** now

Using the above mutation your new query would look like this:

.. code:: graphql
mutation myFirstMutation {
createPerson(personData: {name:"Peter", age: 24}) {
person {
name,
age
}
}
}
InputObjectTypes can also be fields of InputObjectTypes allowing you to have
as complex of input data as you need

.. code:: python
import graphene
class LatLngInput(graphene.InputObjectType):
lat = graphene.Float()
lng = graphene.Float()
#A location has a latlng associated to it
class LocationInput(graphene.InputObjectType):
name = graphene.String()
latlng = graphene.InputField(LatLngInputType)

0 comments on commit dda294d

Please sign in to comment.