Skip to content

Commit bff187a

Browse files
committed
Merge pull request #54 from graphql-python/releases/0.5.0
Version 0.5.0 reached! Compatible with GraphQL April 2016 spec 😎
2 parents 8ea043a + f2175f5 commit bff187a

File tree

190 files changed

+6128
-4306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+6128
-4306
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ python:
88
- pypy
99
cache: pip
1010
install:
11-
- pip install --cache-dir $HOME/.cache/pip pytest-cov coveralls flake8 import-order gevent==1.1b5 six>=1.10.0
11+
- pip install --cache-dir $HOME/.cache/pip pytest-cov pytest-mock coveralls flake8 isort==3.9.6 gevent==1.1b5 six>=1.10.0 pypromise>=0.4.0
1212
- pip install --cache-dir $HOME/.cache/pip pytest>=2.7.3 --upgrade
1313
- pip install -e .
1414
script:
1515
- flake8
16-
- py.test --cov=graphql tests
16+
- py.test --cov=graphql graphql tests
1717
after_success:
1818
- coveralls
1919
matrix:
2020
include:
2121
- python: "3.5"
2222
script:
2323
- flake8
24-
- import-order graphql
25-
- py.test --cov=graphql tests tests_py35
24+
- isort --check-only graphql/ -rc
25+
- py.test --cov=graphql graphql tests tests_py35

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

graphql/__init__.py

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'''
2-
GraphQL provides a Python implementation for the GraphQL specification
2+
GraphQL.js provides a reference implementation for the GraphQL specification
33
but is also a useful utility for operating on GraphQL files and building
44
sophisticated tools.
55
@@ -14,4 +14,200 @@
1414
1515
This also includes utility functions for operating on GraphQL types and
1616
GraphQL documents to facilitate building tools.
17+
18+
You may also import from each sub-directory directly. For example, the
19+
following two import statements are equivalent:
20+
21+
from graphql import parse
22+
from graphql.language.base import parse
1723
'''
24+
25+
26+
# The primary entry point into fulfilling a GraphQL request.
27+
from .graphql import (
28+
graphql
29+
)
30+
31+
32+
# Create and operate on GraphQL type definitions and schema.
33+
from .type import ( # no import order
34+
GraphQLSchema,
35+
36+
# Definitions
37+
GraphQLScalarType,
38+
GraphQLObjectType,
39+
GraphQLInterfaceType,
40+
GraphQLUnionType,
41+
GraphQLEnumType,
42+
GraphQLInputObjectType,
43+
GraphQLList,
44+
GraphQLNonNull,
45+
46+
# Scalars
47+
GraphQLInt,
48+
GraphQLFloat,
49+
GraphQLString,
50+
GraphQLBoolean,
51+
GraphQLID,
52+
53+
# Predicates
54+
is_type,
55+
is_input_type,
56+
is_output_type,
57+
is_leaf_type,
58+
is_composite_type,
59+
is_abstract_type,
60+
61+
# Un-modifiers
62+
get_nullable_type,
63+
get_named_type,
64+
)
65+
66+
67+
# Parse and operate on GraphQL language source files.
68+
from .language.base import ( # no import order
69+
Source,
70+
get_location,
71+
72+
# Parse
73+
parse,
74+
parse_value,
75+
76+
# Print
77+
print_ast,
78+
79+
# Visit
80+
visit,
81+
ParallelVisitor,
82+
TypeInfoVisitor,
83+
BREAK,
84+
)
85+
86+
87+
# Execute GraphQL queries.
88+
from .execution import ( # no import order
89+
execute,
90+
)
91+
92+
93+
# Validate GraphQL queries.
94+
from .validation import ( # no import order
95+
validate,
96+
specified_rules,
97+
)
98+
99+
# Create and format GraphQL errors.
100+
from .error import (
101+
GraphQLError,
102+
format_error,
103+
)
104+
105+
106+
# Utilities for operating on GraphQL type schema and parsed sources.
107+
from .utils.base import (
108+
# The GraphQL query recommended for a full schema introspection.
109+
introspection_query,
110+
111+
# Gets the target Operation from a Document
112+
get_operation_ast,
113+
114+
# Build a GraphQLSchema from an introspection result.
115+
build_client_schema,
116+
117+
# Build a GraphQLSchema from a parsed GraphQL Schema language AST.
118+
build_ast_schema,
119+
120+
# Extends an existing GraphQLSchema from a parsed GraphQL Schema
121+
# language AST.
122+
extend_schema,
123+
124+
# Print a GraphQLSchema to GraphQL Schema language.
125+
print_schema,
126+
127+
# Create a GraphQLType from a GraphQL language AST.
128+
type_from_ast,
129+
130+
# Create a JavaScript value from a GraphQL language AST.
131+
value_from_ast,
132+
133+
# Create a GraphQL language AST from a JavaScript value.
134+
ast_from_value,
135+
136+
# A helper to use within recursive-descent visitors which need to be aware of
137+
# the GraphQL type system.
138+
TypeInfo,
139+
140+
# Determine if JavaScript values adhere to a GraphQL type.
141+
is_valid_value,
142+
143+
# Determine if AST values adhere to a GraphQL type.
144+
is_valid_literal_value,
145+
146+
# Concatenates multiple AST together.
147+
concat_ast,
148+
149+
# Comparators for types
150+
is_equal_type,
151+
is_type_sub_type_of,
152+
do_types_overlap,
153+
154+
# Asserts a string is a valid GraphQL name.
155+
assert_valid_name,
156+
)
157+
158+
__all__ = (
159+
'graphql',
160+
'GraphQLBoolean',
161+
'GraphQLEnumType',
162+
'GraphQLFloat',
163+
'GraphQLID',
164+
'GraphQLInputObjectType',
165+
'GraphQLInt',
166+
'GraphQLInterfaceType',
167+
'GraphQLList',
168+
'GraphQLNonNull',
169+
'GraphQLObjectType',
170+
'GraphQLScalarType',
171+
'GraphQLSchema',
172+
'GraphQLString',
173+
'GraphQLUnionType',
174+
'get_named_type',
175+
'get_nullable_type',
176+
'is_abstract_type',
177+
'is_composite_type',
178+
'is_input_type',
179+
'is_leaf_type',
180+
'is_output_type',
181+
'is_type',
182+
'BREAK',
183+
'ParallelVisitor',
184+
'Source',
185+
'TypeInfoVisitor',
186+
'get_location',
187+
'parse',
188+
'parse_value',
189+
'print_ast',
190+
'visit',
191+
'execute',
192+
'specified_rules',
193+
'validate',
194+
'GraphQLError',
195+
'format_error',
196+
'TypeInfo',
197+
'assert_valid_name',
198+
'ast_from_value',
199+
'build_ast_schema',
200+
'build_client_schema',
201+
'concat_ast',
202+
'do_types_overlap',
203+
'extend_schema',
204+
'get_operation_ast',
205+
'introspection_query',
206+
'is_equal_type',
207+
'is_type_sub_type_of',
208+
'is_valid_literal_value',
209+
'is_valid_value',
210+
'print_schema',
211+
'type_from_ast',
212+
'value_from_ast',
213+
)

0 commit comments

Comments
 (0)