Skip to content

Commit ed200db

Browse files
committed
Added documentation converter using panic
1 parent 2d55d89 commit ed200db

File tree

2 files changed

+36
-73
lines changed

2 files changed

+36
-73
lines changed

README.rst

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
Graphene |Build Status| |Coverage Status|
2-
=========================================
1+
|Graphene Logo| `Graphene <http://graphene-python.org>`__ |Build Status| |PyPI version| |Coverage Status|
2+
=========================================================================================================
33

4-
Graphene is a Python library for creating GraphQL schemas/types easly.
5-
It maps the models/fields to internal GraphQL objects without effort.
6-
Including automatic `Django models`_ conversion.
4+
Graphene is a Python library for building GraphQL schemas/types fast and
5+
easily. \* **Easy to use:** It maps the models/fields to internal
6+
GraphQL objects without effort. \* **Relay:** Graphene has builtin
7+
support for Relay \* **Django:** Automatic *Django model* mapping to
8+
Graphene Types. *See an `example
9+
Django <http://github.com/graphql-python/swapi-graphene>`__
10+
implementation*
711

812
Installation
913
------------
@@ -13,89 +17,46 @@ For instaling graphene, just run this command in your shell
1317
.. code:: bash
1418
1519
pip install graphene
20+
# Or in case of need Django model support
21+
pip install graphene[django]
1622
17-
Usage
18-
-----
23+
Examples
24+
--------
1925

20-
Example code of a GraphQL schema using Graphene:
21-
22-
Schema definition
23-
~~~~~~~~~~~~~~~~~
26+
Here is one example for get you started:
2427

2528
.. code:: python
2629
27-
class Character(graphene.Interface):
28-
id = graphene.IDField()
29-
name = graphene.StringField()
30-
friends = graphene.ListField('self')
31-
32-
def resolve_friends(self, args, *_):
33-
return [Human(f) for f in self.instance.friends]
30+
class Query(graphene.ObjectType):
31+
hello = graphene.StringField(description='A typical hello world')
32+
ping = graphene.StringField(description='Ping someone',
33+
to=graphene.Argument(graphene.String))
3434
35-
class Human(Character):
36-
homePlanet = graphene.StringField()
35+
def resolve_hello(self, args, info):
36+
return 'World'
3737
38-
class Query(graphene.ObjectType):
39-
human = graphene.Field(Human)
38+
def resolve_ping(self, args, info):
39+
return 'Pinging {}'.format(args.get('to'))
4040
4141
schema = graphene.Schema(query=Query)
4242
43-
Querying
44-
~~~~~~~~
45-
46-
Querying ``graphene.Schema`` is as simple as:
43+
Then Querying ``graphene.Schema`` is as simple as:
4744

4845
.. code:: python
4946
5047
query = '''
51-
query HeroNameQuery {
52-
hero {
53-
name
54-
}
48+
query SayHello {
49+
hello
50+
ping(to:'peter')
5551
}
5652
'''
5753
result = schema.execute(query)
5854
59-
Relay Schema
60-
~~~~~~~~~~~~
55+
If you want to learn even more, you can also check the following
56+
examples:
6157

62-
Graphene also supports Relay, check the `Starwars Relay example`_!
63-
64-
.. code:: python
65-
66-
class Ship(relay.Node):
67-
'''A ship in the Star Wars saga'''
68-
name = graphene.StringField(description='The name of the ship.')
69-
70-
@classmethod
71-
def get_node(cls, id):
72-
return Ship(getShip(id))
73-
74-
75-
class Query(graphene.ObjectType):
76-
ships = relay.ConnectionField(Ship, description='The ships used by the faction.')
77-
node = relay.NodeField()
78-
79-
@resolve_only_args
80-
def resolve_ships(self):
81-
return [Ship(s) for s in getShips()]
82-
83-
Django+Relay Schema
84-
~~~~~~~~~~~~~~~~~~~
85-
86-
If you want to use graphene with your Django Models check the `Starwars
87-
Django example`_!
88-
89-
.. code:: python
90-
91-
class Ship(DjangoNode):
92-
class Meta:
93-
model = YourDjangoModelHere
94-
# only_fields = ('id', 'name') # Only map this fields from the model
95-
# excluxe_fields ('field_to_excluxe', ) # Exclude mapping this fields from the model
96-
97-
class Query(graphene.ObjectType):
98-
node = relay.NodeField()
58+
- Relay Schema: `Starwars Relay example <examples/starwars_relay>`__
59+
- Django: `Starwars Django example <examples/starwars_django>`__
9960

10061
Contributing
10162
------------
@@ -112,11 +73,10 @@ After developing, the full test suite can be evaluated by running:
11273
11374
python setup.py test # Use --pytest-args="-v -s" for verbose mode
11475
115-
.. _Django models: #djangorelay-schema
116-
.. _Starwars Relay example: tests/starwars_relay
117-
.. _Starwars Django example: tests/starwars_django
118-
76+
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
11977
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene.svg?branch=master
12078
:target: https://travis-ci.org/graphql-python/graphene
79+
.. |PyPI version| image:: https://badge.fury.io/py/graphene.svg
80+
:target: https://badge.fury.io/py/graphene
12181
.. |Coverage Status| image:: https://coveralls.io/repos/graphql-python/graphene/badge.svg?branch=master&service=github
12282
:target: https://coveralls.io/github/graphql-python/graphene?branch=master

bin/convert_documentation

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
pandoc README.md --from markdown --to rst -s -o README.rst

0 commit comments

Comments
 (0)