Added documentation converter using panic

This commit is contained in:
Syrus Akbary 2015-10-29 23:48:13 -07:00
parent 2d55d89047
commit ed200db1f8
2 changed files with 37 additions and 74 deletions

View File

@ -1,9 +1,13 @@
Graphene |Build Status| |Coverage Status| |Graphene Logo| `Graphene <http://graphene-python.org>`__ |Build Status| |PyPI version| |Coverage Status|
========================================= =========================================================================================================
Graphene is a Python library for creating GraphQL schemas/types easly. Graphene is a Python library for building GraphQL schemas/types fast and
It maps the models/fields to internal GraphQL objects without effort. easily. \* **Easy to use:** It maps the models/fields to internal
Including automatic `Django models`_ conversion. GraphQL objects without effort. \* **Relay:** Graphene has builtin
support for Relay \* **Django:** Automatic *Django model* mapping to
Graphene Types. *See an `example
Django <http://github.com/graphql-python/swapi-graphene>`__
implementation*
Installation Installation
------------ ------------
@ -13,89 +17,46 @@ For instaling graphene, just run this command in your shell
.. code:: bash .. code:: bash
pip install graphene pip install graphene
# Or in case of need Django model support
pip install graphene[django]
Usage Examples
----- --------
Example code of a GraphQL schema using Graphene: Here is one example for get you started:
Schema definition
~~~~~~~~~~~~~~~~~
.. code:: python .. code:: python
class Character(graphene.Interface):
id = graphene.IDField()
name = graphene.StringField()
friends = graphene.ListField('self')
def resolve_friends(self, args, *_):
return [Human(f) for f in self.instance.friends]
class Human(Character):
homePlanet = graphene.StringField()
class Query(graphene.ObjectType): class Query(graphene.ObjectType):
human = graphene.Field(Human) hello = graphene.StringField(description='A typical hello world')
ping = graphene.StringField(description='Ping someone',
to=graphene.Argument(graphene.String))
def resolve_hello(self, args, info):
return 'World'
def resolve_ping(self, args, info):
return 'Pinging {}'.format(args.get('to'))
schema = graphene.Schema(query=Query) schema = graphene.Schema(query=Query)
Querying Then Querying ``graphene.Schema`` is as simple as:
~~~~~~~~
Querying ``graphene.Schema`` is as simple as:
.. code:: python .. code:: python
query = ''' query = '''
query HeroNameQuery { query SayHello {
hero { hello
name ping(to:'peter')
}
} }
''' '''
result = schema.execute(query) result = schema.execute(query)
Relay Schema If you want to learn even more, you can also check the following
~~~~~~~~~~~~ examples:
Graphene also supports Relay, check the `Starwars Relay example`_! - Relay Schema: `Starwars Relay example <examples/starwars_relay>`__
- Django: `Starwars Django example <examples/starwars_django>`__
.. code:: python
class Ship(relay.Node):
'''A ship in the Star Wars saga'''
name = graphene.StringField(description='The name of the ship.')
@classmethod
def get_node(cls, id):
return Ship(getShip(id))
class Query(graphene.ObjectType):
ships = relay.ConnectionField(Ship, description='The ships used by the faction.')
node = relay.NodeField()
@resolve_only_args
def resolve_ships(self):
return [Ship(s) for s in getShips()]
Django+Relay Schema
~~~~~~~~~~~~~~~~~~~
If you want to use graphene with your Django Models check the `Starwars
Django example`_!
.. code:: python
class Ship(DjangoNode):
class Meta:
model = YourDjangoModelHere
# only_fields = ('id', 'name') # Only map this fields from the model
# excluxe_fields ('field_to_excluxe', ) # Exclude mapping this fields from the model
class Query(graphene.ObjectType):
node = relay.NodeField()
Contributing Contributing
------------ ------------
@ -112,11 +73,10 @@ After developing, the full test suite can be evaluated by running:
python setup.py test # Use --pytest-args="-v -s" for verbose mode python setup.py test # Use --pytest-args="-v -s" for verbose mode
.. _Django models: #djangorelay-schema .. |Graphene Logo| image:: http://graphene-python.org/favicon.png
.. _Starwars Relay example: tests/starwars_relay
.. _Starwars Django example: tests/starwars_django
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master .. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master
:target: https://travis-ci.org/graphql-python/graphene :target: https://travis-ci.org/graphql-python/graphene
.. |PyPI version| image:: https://badge.fury.io/py/graphene.svg
:target: https://badge.fury.io/py/graphene
.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene/badge.svg?branch=master&service=github .. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/graphql-python/graphene?branch=master :target: https://coveralls.io/github/graphql-python/graphene?branch=master

3
bin/convert_documentation Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
pandoc README.md --from markdown --to rst -s -o README.rst