@@ -11,28 +11,28 @@ a query language for APIs created by Facebook.
11
11
[ ![ Dependency Updates] ( https://pyup.io/repos/github/graphql-python/graphql-core-next/shield.svg )] ( https://pyup.io/repos/github/graphql-python/graphql-core-next/ )
12
12
[ ![ Python 3 Status] ( https://pyup.io/repos/github/graphql-python/graphql-core-next/python-3-shield.svg )] ( https://pyup.io/repos/github/graphql-python/graphql-core-next/ )
13
13
14
- The current version 1.0.1 of GraphQL-core-next is up-to-date with GraphQL.js
15
- version 14.0.2. All parts of the API are covered by an extensive test suite of
16
- currently 1615 unit tests.
14
+ The current version 1.0.1 of GraphQL-core-next is up-to-date with GraphQL.js version
15
+ 14.0.2. All parts of the API are covered by an extensive test suite of currently 1615
16
+ unit tests.
17
17
18
18
19
19
## Documentation
20
20
21
21
A more detailed documentation for GraphQL-core-next can be found at
22
22
[ graphql-core-next.readthedocs.io] ( https://graphql-core-next.readthedocs.io/ ) .
23
23
24
- There will be also [ blog articles] ( https://cito.github.io/tags/graphql/ )
25
- with more usage examples.
24
+ There will be also [ blog articles] ( https://cito.github.io/tags/graphql/ ) with more usage
25
+ examples.
26
26
27
27
28
28
## Getting started
29
29
30
30
An overview of GraphQL in general is available in the
31
31
[ README] ( https://github.com/facebook/graphql/blob/master/README.md ) for the
32
32
[ Specification for GraphQL] ( https://github.com/facebook/graphql ) . That overview
33
- describes a simple set of GraphQL examples that exist as [ tests] ( tests )
34
- in this repository. A good way to get started with this repository is to walk
35
- through that README and the corresponding tests in parallel.
33
+ describes a simple set of GraphQL examples that exist as [ tests] ( tests ) in this
34
+ repository. A good way to get started with this repository is to walk through that
35
+ README and the corresponding tests in parallel.
36
36
37
37
38
38
## Installation
@@ -41,16 +41,16 @@ GraphQL-core-next can be installed from PyPI using the built-in pip command:
41
41
42
42
python -m pip install graphql-core-next
43
43
44
- Alternatively, you can also use [ pipenv] ( https://docs.pipenv.org/ ) for
45
- installation in a virtual environment:
44
+ Alternatively, you can also use [ pipenv] ( https://docs.pipenv.org/ ) for installation in a
45
+ virtual environment:
46
46
47
47
pipenv install graphql-core-next
48
48
49
49
50
50
## Usage
51
51
52
- GraphQL-core-next provides two important capabilities: building a type schema,
53
- and serving queries against that type schema.
52
+ GraphQL-core-next provides two important capabilities: building a type schema, and
53
+ serving queries against that type schema.
54
54
55
55
First, build a GraphQL type schema which maps to your code base:
56
56
@@ -68,20 +68,19 @@ schema = GraphQLSchema(
68
68
}))
69
69
```
70
70
71
- This defines a simple schema with one type and one field, that resolves
72
- to a fixed value. The ` resolve ` function can return a value, a co-routine
73
- object or a list of these. It takes two positional arguments; the first one
74
- provides the root or the resolved parent field, the second one provides a
75
- ` GraphQLResolveInfo ` object which contains information about the execution
76
- state of the query, including a ` context ` attribute holding per-request state
77
- such as authentication information or database session. Any GraphQL arguments
78
- are passed to the ` resolve ` functions as individual keyword arguments.
79
-
80
- Note that the signature of the resolver functions is a bit different in
81
- GraphQL.js, where the context is passed separately and arguments are passed
82
- as a single object. Also note that GraphQL fields must be passed as a
83
- ` GraphQLField ` object explicitly. Similarly, GraphQL arguments must be
84
- passed as ` GraphQLArgument ` objects.
71
+ This defines a simple schema with one type and one field, that resolves to a fixed
72
+ value. The ` resolve ` function can return a value, a co-routine object or a list of
73
+ these. It takes two positional arguments; the first one provides the root or the
74
+ resolved parent field, the second one provides a ` GraphQLResolveInfo ` object which
75
+ contains information about the execution state of the query, including a ` context `
76
+ attribute holding per-request state such as authentication information or database
77
+ session. Any GraphQL arguments are passed to the ` resolve ` functions as individual
78
+ keyword arguments.
79
+
80
+ Note that the signature of the resolver functions is a bit different in GraphQL.js,
81
+ where the context is passed separately and arguments are passed as a single object.
82
+ Also note that GraphQL fields must be passed as a ` GraphQLField ` object explicitly.
83
+ Similarly, GraphQL arguments must be passed as ` GraphQLArgument ` objects.
85
84
86
85
A more complex example is included in the top level [ tests] ( tests ) directory.
87
86
@@ -101,8 +100,8 @@ This runs a query fetching the one field defined, and then prints the result:
101
100
ExecutionResult(data = {' hello' : ' world' }, errors = None )
102
101
```
103
102
104
- The ` graphql_sync ` function will first ensure the query is syntactically
105
- and semantically valid before executing it, reporting errors otherwise.
103
+ The ` graphql_sync ` function will first ensure the query is syntactically and
104
+ semantically valid before executing it, reporting errors otherwise.
106
105
107
106
``` python
108
107
from graphql import graphql_sync
@@ -120,9 +119,9 @@ ExecutionResult(data=None, errors=[GraphQLError(
120
119
locations = [SourceLocation(line = 1 , column = 3 )])])
121
120
```
122
121
123
- The ` graphql_sync ` function assumes that all resolvers return values
124
- synchronously. By using coroutines as resolvers, you can also create
125
- results in an asynchronous fashion with the ` graphql ` function.
122
+ The ` graphql_sync ` function assumes that all resolvers return values synchronously. By
123
+ using coroutines as resolvers, you can also create results in an asynchronous fashion
124
+ with the ` graphql ` function.
126
125
127
126
``` python
128
127
import asyncio
@@ -161,29 +160,29 @@ finally:
161
160
162
161
## Goals and restrictions
163
162
164
- GraphQL-core-next tries to reproduce the code of the reference implementation
165
- GraphQL.js in Python as closely as possible and to stay up-to-date with
166
- the latest development of GraphQL.js.
163
+ GraphQL-core-next tries to reproduce the code of the reference implementation GraphQL.js
164
+ in Python as closely as possible and to stay up-to-date with the latest development of
165
+ GraphQL.js.
167
166
168
167
It has been created as an alternative and potential successor to
169
- [ GraphQL-core] ( https://github.com/graphql-python/graphql-core ) ,
170
- a prior work by Syrus Akbary, based on an older version of GraphQL.js and
171
- also targeting older Python versions. GraphQL-core also serves as as the
172
- foundation for [ Graphene] ( http://graphene-python.org/ ) , a more high-level
173
- framework for building GraphQL APIs in Python. Some parts of GraphQL-core-next
174
- have been inspired by GraphQL-core or directly taken over with only slight
175
- modifications, but most of the code has been re-implemented from scratch,
176
- replicating the latest code in GraphQL.js very closely and adding type hints
177
- for Python. Though GraphQL-core has also been updated and modernized to some
178
- extend, it might be replaced by GraphQL-core-next in the future.
168
+ [ GraphQL-core] ( https://github.com/graphql-python/graphql-core ) , a prior work
169
+ by Syrus Akbary, based on an older version of GraphQL.js and also targeting
170
+ older Python versions. GraphQL-core also serves as as the foundation for
171
+ [ Graphene] ( http://graphene-python.org/ ) , a more high-level framework for building
172
+ GraphQL APIs in Python. Some parts of GraphQL-core-next have been inspired by
173
+ GraphQL-core or directly taken over with only slight modifications, but most of the code
174
+ has been re-implemented from scratch, replicating the latest code in GraphQL.js very
175
+ closely and adding type hints for Python. Though GraphQL-core has also been updated and
176
+ modernized to some extend, it might be replaced by GraphQL-core-next in the future.
179
177
180
178
Design goals for the GraphQL-core-next library are:
181
179
182
- * to be a simple, cruft-free, state-of-the-art implementation of GraphQL using
183
- current library and language versions
184
- * to be very close to the GraphQL.js reference implementation, while still
185
- using a Pythonic API and code style
180
+ * to be a simple, cruft-free, state-of-the-art implementation of GraphQL using current
181
+ library and language versions
182
+ * to be very close to the GraphQL.js reference implementation, while still using a
183
+ Pythonic API and code style
186
184
* making use of Python type hints, similar to how GraphQL.js makes use of Flow
185
+ * using of [ black] ( https://github.com/ambv/black ) for automatic code formatting
187
186
* replicate the complete Mocha-based test suite of GraphQL.js using
188
187
[ pytest] ( https://docs.pytest.org/ )
189
188
@@ -192,8 +191,7 @@ Some restrictions (mostly in line with the design goals):
192
191
* requires Python 3.6 or 3.7
193
192
* does not support some already deprecated methods and options of GraphQL.js
194
193
* supports asynchronous operations only via async.io
195
- * does not support additional executors and middleware like GraphQL-core
196
- (we are considering adding middleware later though)
194
+ (does not support the additional executors in GraphQL-core)
197
195
* the benchmarks have not yet been ported to Python
198
196
199
197
0 commit comments