Skip to content

Way to 0.4.13 #49

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 16 commits into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions bin/autolinter
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

# Install the required scripts with
# pip install autoflake autopep8 isort
autoflake ./graphql/ ./tests/ -r --remove-unused-variables --in-place
autopep8 ./tests/ ./graphql/ -r --in-place --experimental --aggressive --max-line-length 120
isort -rc ./tests/ ./graphql/
24 changes: 9 additions & 15 deletions graphql/core/execution/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@
from ..error import GraphQLError
from ..language import ast
from ..pyutils.defer import DeferredException
from ..type.definition import (
GraphQLInterfaceType,
GraphQLUnionType,
)
from ..type.directives import (
GraphQLIncludeDirective,
GraphQLSkipDirective,
)
from ..type.introspection import (
SchemaMetaFieldDef,
TypeMetaFieldDef,
TypeNameMetaFieldDef,
)
from ..type.definition import GraphQLInterfaceType, GraphQLUnionType
from ..type.directives import GraphQLIncludeDirective, GraphQLSkipDirective
from ..type.introspection import (SchemaMetaFieldDef, TypeMetaFieldDef,
TypeNameMetaFieldDef)
from ..utils.type_from_ast import type_from_ast
from .values import get_argument_values, get_variable_values

Expand Down Expand Up @@ -97,7 +88,7 @@ def __init__(self, data=None, errors=None, invalid=False):
errors = [
error.value if isinstance(error, DeferredException) else error
for error in errors
]
]

self.errors = errors

Expand Down Expand Up @@ -170,7 +161,9 @@ def collect_fields(ctx, runtime_type, selection_set, fields, prev_fragment_names
fields[name].append(selection)

elif isinstance(selection, ast.InlineFragment):
if not should_include_node(ctx, directives) or not does_fragment_condition_match(ctx, selection, runtime_type):
if not should_include_node(
ctx, directives) or not does_fragment_condition_match(
ctx, selection, runtime_type):
continue

collect_fields(ctx, runtime_type, selection.selection_set, fields, prev_fragment_names)
Expand Down Expand Up @@ -255,6 +248,7 @@ def get_field_entry_key(node):


class ResolveInfo(object):

def __init__(self, field_name, field_asts, return_type, parent_type, context):
self.field_name = field_name
self.field_asts = field_asts
Expand Down
14 changes: 9 additions & 5 deletions graphql/core/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
from ..language.parser import parse
from ..language.source import Source
from ..pyutils.default_ordered_dict import DefaultOrderedDict
from ..pyutils.defer import Deferred, DeferredDict, DeferredList, defer, succeed
from ..type import GraphQLEnumType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, \
GraphQLScalarType, GraphQLUnionType
from ..pyutils.defer import (Deferred, DeferredDict, DeferredList, defer,
succeed)
from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
GraphQLUnionType)
from ..validation import validate
from .base import ExecutionContext, ExecutionResult, ResolveInfo, Undefined, collect_fields, default_resolve_fn, \
get_field_def, get_operation_root_type
from .base import (ExecutionContext, ExecutionResult, ResolveInfo, Undefined,
collect_fields, default_resolve_fn, get_field_def,
get_operation_root_type)


class Executor(object):

def __init__(self, execution_middlewares=None, default_resolver=default_resolve_fn, map_type=dict):
assert issubclass(map_type, collections.MutableMapping)

Expand Down
1 change: 1 addition & 0 deletions graphql/core/execution/middlewares/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def handle_future_result(future):


class AsyncioExecutionMiddleware(object):

@staticmethod
def run_resolve_fn(resolver, original_resolver):
result = resolver()
Expand Down
1 change: 1 addition & 0 deletions graphql/core/execution/middlewares/gevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def resolve_something(context, _*):


class GeventExecutionMiddleware(object):

@staticmethod
def run_resolve_fn(resolver, original_resolver):
if resolver_has_tag(original_resolver, 'run_in_greenlet'):
Expand Down
1 change: 1 addition & 0 deletions graphql/core/execution/middlewares/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class SynchronousExecutionMiddleware(object):

@staticmethod
def run_resolve_fn(resolver, original_resolver):
result = resolver()
Expand Down
12 changes: 4 additions & 8 deletions graphql/core/execution/values.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import collections
import json

from six import string_types

from ..error import GraphQLError
from ..language.printer import print_ast
from ..type import (
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLList,
GraphQLNonNull,
GraphQLScalarType,
is_input_type
)
from ..type import (GraphQLEnumType, GraphQLInputObjectType, GraphQLList,
GraphQLNonNull, GraphQLScalarType, is_input_type)
from ..utils.is_valid_value import is_valid_value
from ..utils.type_from_ast import type_from_ast
from ..utils.value_from_ast import value_from_ast
Expand Down
1 change: 1 addition & 0 deletions graphql/core/language/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


class LanguageError(GraphQLError):

def __init__(self, source, position, description):
location = get_location(source, position)
super(LanguageError, self).__init__(
Expand Down
2 changes: 2 additions & 0 deletions graphql/core/language/lexer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from six import unichr

from .error import LanguageError

__all__ = ['Token', 'Lexer', 'TokenKind',
Expand Down
1 change: 1 addition & 0 deletions graphql/core/language/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from six import string_types

from . import ast
from .error import LanguageError
from .lexer import Lexer, TokenKind, get_token_desc, get_token_kind_desc
Expand Down
1 change: 1 addition & 0 deletions graphql/core/language/printer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json

from .visitor import Visitor, visit

__all__ = ['print_ast']
Expand Down
2 changes: 1 addition & 1 deletion graphql/core/language/visitor.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from copy import copy

import six

from . import ast
from .visitor_meta import QUERY_DOCUMENT_KEYS, VisitorMeta


BREAK = object()
REMOVE = object()

Expand Down
1 change: 1 addition & 0 deletions graphql/core/language/visitor_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@


class VisitorMeta(type):

def __new__(cls, name, bases, attrs):
enter_handlers = {}
leave_handlers = {}
Expand Down
3 changes: 3 additions & 0 deletions graphql/core/pyutils/defer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
# THE SOFTWARE.
import collections
import sys

from six import reraise

__all__ = ("Deferred", "AlreadyCalledDeferred", "DeferredException",
Expand Down Expand Up @@ -511,6 +512,7 @@ def _cb_deferred(self, result, key, succeeded):


class DeferredDict(_ResultCollector):

def __init__(self, mapping):
super(DeferredDict, self).__init__()
assert isinstance(mapping, collections.Mapping)
Expand All @@ -519,6 +521,7 @@ def __init__(self, mapping):


class DeferredList(_ResultCollector):

def __init__(self, sequence):
super(DeferredList, self).__init__()
assert isinstance(sequence, collections.Sequence)
Expand Down
4 changes: 3 additions & 1 deletion graphql/core/type/definition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import collections
import copy
import re

from ..language import ast


Expand Down Expand Up @@ -466,7 +467,8 @@ def define_types(union_type, types):
if callable(types):
types = types()

assert isinstance(types, (list, tuple)) and len(types) > 0, 'Must provide types for Union {}.'.format(union_type.name)
assert isinstance(types, (list, tuple)) and len(
types) > 0, 'Must provide types for Union {}.'.format(union_type.name)
has_resolve_type_fn = callable(union_type._resolve_type)

for type in types:
Expand Down
19 changes: 6 additions & 13 deletions graphql/core/type/introspection.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
from collections import OrderedDict

from ..language.printer import print_ast
from ..utils.ast_from_value import ast_from_value
from .definition import (
GraphQLArgument,
GraphQLEnumType,
GraphQLEnumValue,
GraphQLField,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
GraphQLUnionType,
)
from .definition import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
GraphQLField, GraphQLInputObjectType,
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
GraphQLObjectType, GraphQLScalarType,
GraphQLUnionType)
from .scalars import GraphQLBoolean, GraphQLString

__Schema = GraphQLObjectType(
Expand Down
8 changes: 2 additions & 6 deletions graphql/core/type/scalars.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from six import text_type
from ..language.ast import (
BooleanValue,
FloatValue,
IntValue,
StringValue,
)

from ..language.ast import BooleanValue, FloatValue, IntValue, StringValue
from .definition import GraphQLScalarType

# Integers are only safe when between -(2^53 - 1) and 2^53 - 1 due to being
Expand Down
30 changes: 9 additions & 21 deletions graphql/core/type/schema.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from collections import OrderedDict
from .definition import (
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLUnionType,
)
from .directives import GraphQLDirective, GraphQLIncludeDirective, GraphQLSkipDirective

from ..utils.type_comparators import is_equal_type, is_type_sub_type_of
from .definition import (GraphQLInputObjectType, GraphQLInterfaceType,
GraphQLList, GraphQLNonNull, GraphQLObjectType,
GraphQLUnionType)
from .directives import (GraphQLDirective, GraphQLIncludeDirective,
GraphQLSkipDirective)
from .introspection import IntrospectionSchema


Expand Down Expand Up @@ -50,7 +48,7 @@ def __init__(self, query, mutation=None, subscription=None, directives=None):
assert all(isinstance(d, GraphQLDirective) for d in directives), \
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
directives
)
)

self._directives = directives

Expand Down Expand Up @@ -144,7 +142,7 @@ def assert_object_implements_interface(object, interface):
interface, field_name, object
)

assert is_equal_type(interface_field.type, object_field.type), (
assert is_type_sub_type_of(object_field.type, interface_field.type), (
'{}.{} expects type "{}" but {}.{} provides type "{}".'
).format(interface, field_name, interface_field.type, object, field_name, object_field.type)

Expand All @@ -171,13 +169,3 @@ def assert_object_implements_interface(object, interface):
'"{}" but is not also provided by the '
'interface {}.{}.'
).format(object, field_name, arg_name, object_arg.type, interface, field_name)


def is_equal_type(type_a, type_b):
if isinstance(type_a, GraphQLNonNull) and isinstance(type_b, GraphQLNonNull):
return is_equal_type(type_a.of_type, type_b.of_type)

if isinstance(type_a, GraphQLList) and isinstance(type_b, GraphQLList):
return is_equal_type(type_a.of_type, type_b.of_type)

return type_a is type_b
9 changes: 3 additions & 6 deletions graphql/core/utils/ast_from_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import sys

from six import string_types

from ..language import ast
from ..type.definition import (
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLList,
GraphQLNonNull,
)
from ..type.definition import (GraphQLEnumType, GraphQLInputObjectType,
GraphQLList, GraphQLNonNull)
from ..type.scalars import GraphQLFloat


Expand Down
4 changes: 3 additions & 1 deletion graphql/core/utils/ast_to_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def ast_to_code(ast, indent=0):
Converts an ast into a python code representation of the AST.
"""
code = []
append = lambda line: code.append((' ' * indent) + line)

def append(line):
code.append((' ' * indent) + line)

if isinstance(ast, Node):
append('ast.{}('.format(ast.__class__.__name__))
Expand Down
32 changes: 10 additions & 22 deletions graphql/core/utils/build_ast_schema.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
from collections import OrderedDict

from ..language import ast
from ..type import (
GraphQLArgument,
GraphQLBoolean,
GraphQLEnumType,
GraphQLEnumValue,
GraphQLField,
GraphQLFloat,
GraphQLID,
GraphQLInputObjectField,
GraphQLInputObjectType,
GraphQLInt,
GraphQLInterfaceType,
GraphQLList,
GraphQLNonNull,
GraphQLObjectType,
GraphQLScalarType,
GraphQLSchema,
GraphQLString,
GraphQLUnionType,
)
from ..type import (GraphQLArgument, GraphQLBoolean, GraphQLEnumType,
GraphQLEnumValue, GraphQLField, GraphQLFloat, GraphQLID,
GraphQLInputObjectField, GraphQLInputObjectType,
GraphQLInt, GraphQLInterfaceType, GraphQLList,
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
GraphQLSchema, GraphQLString, GraphQLUnionType)
from ..utils.value_from_ast import value_from_ast


Expand All @@ -41,8 +27,10 @@ def _get_inner_type_name(type_ast):
return type_ast.name.value


_false = lambda *_: False
_none = lambda *_: None
def _false(*_): return False


def _none(*_): return None


def build_ast_schema(document, query_type_name, mutation_type_name=None, subscription_type_name=None):
Expand Down
Loading