Skip to content

Path to 0.5.0 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 72 commits into from
May 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
480bf4c
Make tests relative to package
syrusakbary Apr 19, 2016
83295d8
Tests to demonstrate problem
Apr 19, 2016
47c0530
Proposed fix
Apr 19, 2016
e9ce3d2
Moved all files one dir level to the top, removing core
syrusakbary Apr 21, 2016
5d4def9
Fix errors
syrusakbary Apr 21, 2016
cb4d508
Fixed PEP8 errors
syrusakbary Apr 21, 2016
44e434f
Merge branch 'mixcloud-upstream-release' into releases/0.5.0
syrusakbary Apr 21, 2016
e0e6bc5
Improved import-order package
syrusakbary Apr 21, 2016
2528d1d
Fixed isort bug version
syrusakbary Apr 21, 2016
b58ac1b
Add to unit tests to ensure test accepts both edits of enter and leave
Apr 21, 2016
0e439f3
Add test for parseLiteral on ComplexScalar
Apr 21, 2016
546fc28
Extract completeListValue funciton from CompleteValue
Apr 21, 2016
6cf4407
Extract completeLeafValue from CompleteValue
Apr 21, 2016
3b51194
Extract completeObjectValue from CompleteValue
Apr 21, 2016
a033eae
Extract completeAbstractValue from CompleteValue
Apr 21, 2016
968d605
Add invariant for unreachable condition
Apr 21, 2016
12b8ca7
Merge pull request #56 from mixcloud/from-js2
syrusakbary Apr 21, 2016
5158a16
Merge pull request #57 from mixcloud/from-js3
syrusakbary Apr 21, 2016
e54543d
Merge pull request #58 from mixcloud/from-js4
syrusakbary Apr 21, 2016
f811dc9
First iteration for implementing promises approach simplifying executor
syrusakbary Apr 22, 2016
6d7b68c
Improved Promise.all() to accept non-promise items
syrusakbary Apr 23, 2016
0b15212
Execute with promises
syrusakbary Apr 23, 2016
d8df44a
Improved code with PEP8, Flake8, isort
syrusakbary Apr 23, 2016
5385c83
Removed defer from graphql package
syrusakbary Apr 23, 2016
0844623
Refactored executor tests
syrusakbary Apr 23, 2016
c3b08e1
Refactored promise code
syrusakbary Apr 23, 2016
1dc8c87
Added pool to Thread executor
syrusakbary Apr 24, 2016
b881789
Merge pull request #59 from graphql-python/features/promises
syrusakbary Apr 26, 2016
cd336fa
Updated README
syrusakbary Apr 27, 2016
0143e08
Improved execute usage. Added exception logger
syrusakbary Apr 27, 2016
199c711
Added pytest mock dependency
syrusakbary Apr 27, 2016
f26bb2e
Fixed flaky test
syrusakbary Apr 27, 2016
f62eddc
[RFC] Proposed change to directive location introspection
syrusakbary Apr 28, 2016
26d03c1
Fixed errors
syrusakbary Apr 28, 2016
8fc685d
Improved sorts and schema logic
syrusakbary Apr 28, 2016
daf9433
Fix import execute function
syrusakbary Apr 28, 2016
78875c2
Add tests confirming missing operation
syrusakbary Apr 30, 2016
ec9be9a
[RFC] Directives in schema language
syrusakbary Apr 30, 2016
8232865
Fixed import order
syrusakbary Apr 30, 2016
10879e4
Updating schema parser to more closely match current state of RFC
syrusakbary Apr 30, 2016
c957874
[RFC] Add Schema Definition to IDL.
syrusakbary Apr 30, 2016
7d6aa95
Improved Enum type docs and Include test for extending a schema that …
syrusakbary Apr 30, 2016
cd38ff6
Include test for unreferenced interface
syrusakbary Apr 30, 2016
5fc4cdb
Naming similarity
syrusakbary Apr 30, 2016
978b834
Move getTypeOf to execute.js and rename to defaultResolveTypeFn to mi…
syrusakbary May 1, 2016
3c5ea56
Small fixes in runtime_type
syrusakbary May 1, 2016
747c64a
Removed default object value in graphql query. Add tests and refine d…
syrusakbary May 1, 2016
078c3a7
Add GraphQLSchema types field, refactored code and added extra comments
syrusakbary May 1, 2016
d512398
Fixed flake8 errors
syrusakbary May 1, 2016
63da27a
Improve coercion error messages
syrusakbary May 1, 2016
c998efd
Clean up tests
syrusakbary May 1, 2016
c085214
Fixed tests
syrusakbary May 1, 2016
5595fc9
Fixed import order
syrusakbary May 1, 2016
308d984
Spec compliant @skip/@include
syrusakbary May 1, 2016
c4c618c
Remove non spec compliant directives test
syrusakbary May 1, 2016
a91c06f
Add tests for type comparators
syrusakbary May 1, 2016
0a4c098
Add sanity checks for schema to allow only a single query, mutation, …
syrusakbary May 1, 2016
f010b92
RFC: Return type overlap validation
syrusakbary May 1, 2016
2879aaf
Fixed PEP8 error
syrusakbary May 1, 2016
a7d822c
First phase of passing the context to the resolver function
syrusakbary May 1, 2016
1e910db
[RFC] Add explicit context arg to graphql execution
syrusakbary May 3, 2016
1acdf34
Fixed enum type tests
syrusakbary May 3, 2016
de5cf4f
Make imports global
syrusakbary May 3, 2016
9dcaee2
Fixed import order, __all__
syrusakbary May 3, 2016
9cdf5b9
Fixed tests
syrusakbary May 3, 2016
a4caacc
Fixed starwars tests and add introspection tests
syrusakbary May 3, 2016
f8b3b76
Use pypromise package for Promises
syrusakbary May 4, 2016
1b602dd
Simplified Asyncio executor
syrusakbary May 4, 2016
5b8a76d
Fixed travis install
syrusakbary May 4, 2016
91dfe61
Updated pypromise version requirement
syrusakbary May 4, 2016
cec4c68
Updated promise sorts
syrusakbary May 4, 2016
f2175f5
Improved exception handling
syrusakbary May 4, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ python:
- pypy
cache: pip
install:
- pip install --cache-dir $HOME/.cache/pip pytest-cov coveralls flake8 import-order gevent==1.1b5 six>=1.10.0
- 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
- pip install --cache-dir $HOME/.cache/pip pytest>=2.7.3 --upgrade
- pip install -e .
script:
- flake8
- py.test --cov=graphql tests
- py.test --cov=graphql graphql tests
after_success:
- coveralls
matrix:
include:
- python: "3.5"
script:
- flake8
- import-order graphql
- py.test --cov=graphql tests tests_py35
- isort --check-only graphql/ -rc
- py.test --cov=graphql graphql tests tests_py35
113 changes: 90 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# GraphQL-core

GraphQL for Python
GraphQL for Python.

*This library is a port of [graphql-js](https://github.com/graphql/graphql-js) to Python.*


[![PyPI version](https://badge.fury.io/py/graphql-core.svg)](https://badge.fury.io/py/graphql-core)
[![Build Status](https://travis-ci.org/graphql-python/graphql-core.svg?branch=master)](https://travis-ci.org/graphql-python/graphql-core)
[![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)
[![Public Slack Discussion](https://graphql-slack.herokuapp.com/badge.svg)](https://graphql-slack.herokuapp.com/)

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

## Project Status

This library is a port of [graphql-js](https://github.com/graphql/graphql-js) to Python.

We are currently targeting feature parity with `v0.4.18` of the reference implementation, and are currently on `v0.5.0`.

Please see [issues](https://github.com/graphql-python/graphql-core/issues) for the progress.
For questions, ask [Stack Overflow](http://stackoverflow.com/questions/tagged/graphql).

## Getting Started

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

### Using `graphql-core`
### Using graphql-core

Install from pip:

```sh
pip install graphql-core
```

### Supported Python Versions
`graphql-core` supports the following Python versions:

* `2.7.x`
* `3.3.x`
* `3.4.x`
* `3.5.0`
* `pypy-2.6.1`
GraphQL.js provides two important capabilities: building a type schema, and
serving queries against that type schema.

First, build a GraphQL type schema which maps to your code base.

```python
from graphql import (
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLField,
GraphQLString
)

schema = GraphQLSchema(
query= GraphQLObjectType(
name='RootQueryType',
fields={
'hello': GraphQLField(
type= GraphQLString,
resolve=lambda *_: 'world'
)
}
)
)
```

This defines a simple schema with one type and one field, that resolves
to a fixed value. The `resolve` function can return a value, a promise,
or an array of promises. A more complex example is included in the top
level [tests](graphql/tests) directory.

Then, serve the result of a query against that type schema.

```python
query = '{ hello }'

result = graphql(schema, query)

# Prints
# {
# "data": { "hello": "world" }
# }
print result
```

This runs a query fetching the one field defined. The `graphql` function will
first ensure the query is syntactically and semantically valid before executing
it, reporting errors otherwise.

```python
query = '{ boyhowdy }'

result = graphql(schema, query)

# Prints
# {
# "errors": [
# { "message": "Cannot query field boyhowdy on RootQueryType",
# "locations": [ { "line": 1, "column": 3 } ] }
# ]
# }
print result
```

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

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

Otherwise, by default, the executor will use execute with no concurrency.
* `graphql.execution.executors.asyncio.AsyncioExecutor`: This executor executes the resolvers in the Python asyncio event loop.
* `graphql.execution.executors.asyncio.GeventExecutor`: This executor executes the resolvers in the Gevent event loop.
* `graphql.execution.executors.asyncio.ProcessExecutor`: This executor executes each resolver as a process.
* `graphql.execution.executors.asyncio.ThreadExecutor`: This executor executes each resolver in a Thread.
* `graphql.execution.executors.asyncio.SyncExecutor`: This executor executes each resolver synchronusly (default).

#### Usage

You can specify the executor to use via the executor keyword argument in the `grapqhl.execution.execute` function.

```python
from graphql.execution.execute import execute

execute(schema, ast, executor=SyncExecutor())
```

## Main Contributors

Expand Down
198 changes: 197 additions & 1 deletion graphql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
GraphQL provides a Python implementation for the GraphQL specification
GraphQL.js provides a reference implementation for the GraphQL specification
but is also a useful utility for operating on GraphQL files and building
sophisticated tools.

Expand All @@ -14,4 +14,200 @@

This also includes utility functions for operating on GraphQL types and
GraphQL documents to facilitate building tools.

You may also import from each sub-directory directly. For example, the
following two import statements are equivalent:

from graphql import parse
from graphql.language.base import parse
'''


# The primary entry point into fulfilling a GraphQL request.
from .graphql import (
graphql
)


# Create and operate on GraphQL type definitions and schema.
from .type import ( # no import order
GraphQLSchema,

# Definitions
GraphQLScalarType,
GraphQLObjectType,
GraphQLInterfaceType,
GraphQLUnionType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLList,
GraphQLNonNull,

# Scalars
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLBoolean,
GraphQLID,

# Predicates
is_type,
is_input_type,
is_output_type,
is_leaf_type,
is_composite_type,
is_abstract_type,

# Un-modifiers
get_nullable_type,
get_named_type,
)


# Parse and operate on GraphQL language source files.
from .language.base import ( # no import order
Source,
get_location,

# Parse
parse,
parse_value,

# Print
print_ast,

# Visit
visit,
ParallelVisitor,
TypeInfoVisitor,
BREAK,
)


# Execute GraphQL queries.
from .execution import ( # no import order
execute,
)


# Validate GraphQL queries.
from .validation import ( # no import order
validate,
specified_rules,
)

# Create and format GraphQL errors.
from .error import (
GraphQLError,
format_error,
)


# Utilities for operating on GraphQL type schema and parsed sources.
from .utils.base import (
# The GraphQL query recommended for a full schema introspection.
introspection_query,

# Gets the target Operation from a Document
get_operation_ast,

# Build a GraphQLSchema from an introspection result.
build_client_schema,

# Build a GraphQLSchema from a parsed GraphQL Schema language AST.
build_ast_schema,

# Extends an existing GraphQLSchema from a parsed GraphQL Schema
# language AST.
extend_schema,

# Print a GraphQLSchema to GraphQL Schema language.
print_schema,

# Create a GraphQLType from a GraphQL language AST.
type_from_ast,

# Create a JavaScript value from a GraphQL language AST.
value_from_ast,

# Create a GraphQL language AST from a JavaScript value.
ast_from_value,

# A helper to use within recursive-descent visitors which need to be aware of
# the GraphQL type system.
TypeInfo,

# Determine if JavaScript values adhere to a GraphQL type.
is_valid_value,

# Determine if AST values adhere to a GraphQL type.
is_valid_literal_value,

# Concatenates multiple AST together.
concat_ast,

# Comparators for types
is_equal_type,
is_type_sub_type_of,
do_types_overlap,

# Asserts a string is a valid GraphQL name.
assert_valid_name,
)

__all__ = (
'graphql',
'GraphQLBoolean',
'GraphQLEnumType',
'GraphQLFloat',
'GraphQLID',
'GraphQLInputObjectType',
'GraphQLInt',
'GraphQLInterfaceType',
'GraphQLList',
'GraphQLNonNull',
'GraphQLObjectType',
'GraphQLScalarType',
'GraphQLSchema',
'GraphQLString',
'GraphQLUnionType',
'get_named_type',
'get_nullable_type',
'is_abstract_type',
'is_composite_type',
'is_input_type',
'is_leaf_type',
'is_output_type',
'is_type',
'BREAK',
'ParallelVisitor',
'Source',
'TypeInfoVisitor',
'get_location',
'parse',
'parse_value',
'print_ast',
'visit',
'execute',
'specified_rules',
'validate',
'GraphQLError',
'format_error',
'TypeInfo',
'assert_valid_name',
'ast_from_value',
'build_ast_schema',
'build_client_schema',
'concat_ast',
'do_types_overlap',
'extend_schema',
'get_operation_ast',
'introspection_query',
'is_equal_type',
'is_type_sub_type_of',
'is_valid_literal_value',
'is_valid_value',
'print_schema',
'type_from_ast',
'value_from_ast',
)
Loading