Skip to content

Commit cd336fa

Browse files
committed
Updated README
1 parent b881789 commit cd336fa

File tree

1 file changed

+90
-23
lines changed

1 file changed

+90
-23
lines changed

README.md

Lines changed: 90 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
# GraphQL-core
22

3-
GraphQL for Python
3+
GraphQL for Python.
4+
5+
*This library is a port of [graphql-js](https://github.com/graphql/graphql-js) to Python.*
6+
47

58
[![PyPI version](https://badge.fury.io/py/graphql-core.svg)](https://badge.fury.io/py/graphql-core)
69
[![Build Status](https://travis-ci.org/graphql-python/graphql-core.svg?branch=master)](https://travis-ci.org/graphql-python/graphql-core)
710
[![Coverage Status](https://coveralls.io/repos/graphql-python/graphql-core/badge.svg?branch=master&service=github)](https://coveralls.io/github/graphql-python/graphql-core?branch=master)
811
[![Public Slack Discussion](https://graphql-slack.herokuapp.com/badge.svg)](https://graphql-slack.herokuapp.com/)
912

13+
See more complete documentation at http://graphql.org/ and
14+
http://graphql.org/docs/api-reference-graphql/.
1015

11-
## Project Status
12-
13-
This library is a port of [graphql-js](https://github.com/graphql/graphql-js) to Python.
14-
15-
We are currently targeting feature parity with `v0.4.18` of the reference implementation, and are currently on `v0.5.0`.
16-
17-
Please see [issues](https://github.com/graphql-python/graphql-core/issues) for the progress.
16+
For questions, ask [Stack Overflow](http://stackoverflow.com/questions/tagged/graphql).
1817

1918
## Getting Started
2019

@@ -25,31 +24,99 @@ The overview describes a simple set of GraphQL examples that exist as [tests](te
2524
in this repository. A good way to get started is to walk through that README and the corresponding tests
2625
in parallel.
2726

28-
### Using `graphql-core`
27+
### Using graphql-core
2928

3029
Install from pip:
3130

3231
```sh
3332
pip install graphql-core
3433
```
3534

36-
### Supported Python Versions
37-
`graphql-core` supports the following Python versions:
38-
39-
* `2.7.x`
40-
* `3.3.x`
41-
* `3.4.x`
42-
* `3.5.0`
43-
* `pypy-2.6.1`
35+
GraphQL.js provides two important capabilities: building a type schema, and
36+
serving queries against that type schema.
37+
38+
First, build a GraphQL type schema which maps to your code base.
39+
40+
```python
41+
from graphql import (
42+
graphql,
43+
GraphQLSchema,
44+
GraphQLObjectType,
45+
GraphQLField,
46+
GraphQLString
47+
)
48+
49+
schema = GraphQLSchema(
50+
query= GraphQLObjectType(
51+
name='RootQueryType',
52+
fields={
53+
'hello': GraphQLField(
54+
type= GraphQLString,
55+
resolve=lambda *_: 'world'
56+
)
57+
}
58+
)
59+
)
60+
```
61+
62+
This defines a simple schema with one type and one field, that resolves
63+
to a fixed value. The `resolve` function can return a value, a promise,
64+
or an array of promises. A more complex example is included in the top
65+
level [tests](graphql/tests) directory.
66+
67+
Then, serve the result of a query against that type schema.
68+
69+
```python
70+
query = '{ hello }'
71+
72+
result = graphql(schema, query)
73+
74+
# Prints
75+
# {
76+
# "data": { "hello": "world" }
77+
# }
78+
print result
79+
```
80+
81+
This runs a query fetching the one field defined. The `graphql` function will
82+
first ensure the query is syntactically and semantically valid before executing
83+
it, reporting errors otherwise.
84+
85+
```python
86+
query = '{ boyhowdy }'
87+
88+
result = graphql(schema, query)
89+
90+
# Prints
91+
# {
92+
# "errors": [
93+
# { "message": "Cannot query field boyhowdy on RootQueryType",
94+
# "locations": [ { "line": 1, "column": 3 } ] }
95+
# ]
96+
# }
97+
print result
98+
```
4499

45-
### Built-in Concurrency Support
46-
Support for `3.5.0`'s `asyncio` module for concurrent execution is available via an executor middleware at
47-
`graphql.core.execution.middlewares.asyncio.AsyncioExecutionMiddleware`.
100+
### Executors
48101

49-
Additionally, support for `gevent` is available via
50-
`graphql.core.execution.middlewares.gevent.GeventExecutionMiddleware`.
102+
The graphql query is executed, by default, synchronously (using `SyncExecutor`).
103+
However the following executors are available if we want to resolve our fields in parallel:
51104

52-
Otherwise, by default, the executor will use execute with no concurrency.
105+
* `graphql.execution.executors.asyncio.AsyncioExecutor`: This executor executes the resolvers in the Python asyncio event loop.
106+
* `graphql.execution.executors.asyncio.GeventExecutor`: This executor executes the resolvers in the Gevent event loop.
107+
* `graphql.execution.executors.asyncio.ProcessExecutor`: This executor executes each resolver as a process.
108+
* `graphql.execution.executors.asyncio.ThreadExecutor`: This executor executes each resolver in a Thread.
109+
* `graphql.execution.executors.asyncio.SyncExecutor`: This executor executes each resolver synchronusly (default).
110+
111+
#### Usage
112+
113+
You can specify the executor to use via the executor keyword argument in the `grapqhl.execution.execute` function.
114+
115+
```python
116+
from graphql.execution.execute import execute
117+
118+
execute(schema, ast, executor=SyncExecutor())
119+
```
53120

54121
## Main Contributors
55122

0 commit comments

Comments
 (0)