Skip to content

Commit e6dc32d

Browse files
committed
Move core modules into graphql.core package
1 parent 64a6aba commit e6dc32d

35 files changed

+110
-109
lines changed

graphql/__init__.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
from .executor import execute
2-
from .language import Source, parse
3-
4-
5-
def graphql(schema, request='', root=None, vars=None, operation_name=None):
6-
source = Source(request, 'GraphQL request')
7-
ast = parse(source)
8-
# TODO: validate document
9-
return execute(
10-
schema,
11-
root or object(),
12-
ast,
13-
vars or {},
14-
operation_name
15-
)
1+
from .api import Schema # noqa

graphql/api.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from graphql import graphql as graphql_main
2-
import graphql.type
1+
from graphql.core import graphql as graphql_main
2+
import graphql.core.type as gql_types
33

44
__all__ = ['Schema']
55

@@ -86,7 +86,7 @@ def resolve(self, schema):
8686
if self.args:
8787
for arg_name, arg in self.args.items():
8888
args[arg_name] = arg.resolve(schema)
89-
return graphql.type.GraphQLField(
89+
return gql_types.GraphQLField(
9090
self.typeref.resolve(schema),
9191
args, self.resolver, self.deprecation_reason, self.description
9292
)
@@ -104,22 +104,22 @@ def __init__(self, typerefspec, default_value=None, description=None):
104104
self.description = description
105105

106106
def resolve(self, schema):
107-
return graphql.type.GraphQLArgument(
107+
return gql_types.GraphQLArgument(
108108
self.typeref.resolve(schema),
109109
self.default_value, self.description
110110
)
111111

112112

113113
class Schema(object):
114-
String = InternalTypeRef(graphql.type.GraphQLString)
115-
Int = InternalTypeRef(graphql.type.GraphQLInt)
116-
Float = InternalTypeRef(graphql.type.GraphQLFloat)
117-
Boolean = InternalTypeRef(graphql.type.GraphQLBoolean)
118-
ID = InternalTypeRef(graphql.type.GraphQLID)
114+
String = InternalTypeRef(gql_types.GraphQLString)
115+
Int = InternalTypeRef(gql_types.GraphQLInt)
116+
Float = InternalTypeRef(gql_types.GraphQLFloat)
117+
Boolean = InternalTypeRef(gql_types.GraphQLBoolean)
118+
ID = InternalTypeRef(gql_types.GraphQLID)
119119

120120
Field = LazyField
121121
Argument = LazyArgument
122-
EnumValue = graphql.type.GraphQLEnumValue
122+
EnumValue = gql_types.GraphQLEnumValue
123123

124124
def __init__(self):
125125
self._internal_types = {}
@@ -128,8 +128,8 @@ def __init__(self):
128128
self._mutation_root = None
129129

130130
# Define in the constructor to make functions unbound
131-
self.NonNull = WrappingTypeRef.factory(graphql.type.GraphQLNonNull)
132-
self.List = WrappingTypeRef.factory(graphql.type.GraphQLList)
131+
self.NonNull = WrappingTypeRef.factory(gql_types.GraphQLNonNull)
132+
self.List = WrappingTypeRef.factory(gql_types.GraphQLList)
133133

134134
self.EnumType = self._build_type_definer(self._define_enum)
135135
self.InterfaceType = self._build_type_definer(self._define_interface)
@@ -143,7 +143,7 @@ def _define_enum(self, dct):
143143
for k, v in dct.items():
144144
if isinstance(v, self.EnumValue):
145145
values[k] = v
146-
return graphql.type.GraphQLEnumType(
146+
return gql_types.GraphQLEnumType(
147147
name=dct['__typename__'],
148148
values=values,
149149
description=dct.get('__doc__'),
@@ -154,15 +154,15 @@ def _define_interface(self, dct):
154154
for k, v in dct.items():
155155
if isinstance(v, self.Field):
156156
fields[k] = v
157-
return graphql.type.GraphQLInterfaceType(
157+
return gql_types.GraphQLInterfaceType(
158158
name=dct['__typename__'],
159159
fields=lambda: self._resolve_fields(fields),
160160
description=dct.get('__doc__'),
161161
)
162162

163163
def _define_union(self, dct):
164164
types = [self._public_types[public_type] for public_type in dct['types']]
165-
return graphql.type.GraphQLUnionType(
165+
return gql_types.GraphQLUnionType(
166166
name=dct['__typename__'],
167167
types=types,
168168
resolve_type=dct.get('resolve_type'),
@@ -177,7 +177,7 @@ def _define_object(self, dct):
177177
interfaces = dct.get('__interfaces__')
178178
if interfaces:
179179
interfaces = [self._public_types[public_type] for public_type in interfaces]
180-
return graphql.type.GraphQLObjectType(
180+
return gql_types.GraphQLObjectType(
181181
name=dct['__typename__'],
182182
fields=lambda: self._resolve_fields(fields),
183183
interfaces=interfaces,
@@ -224,7 +224,7 @@ def _define_type(self, cls, name, bases, dct, internal_type_builder):
224224
self._public_types[cls] = internal_type
225225

226226
def to_internal(self):
227-
return graphql.type.GraphQLSchema(self._query_root)
227+
return gql_types.GraphQLSchema(self._query_root)
228228

229229
def execute(self, query, root=None, vars=None, operation_name=None):
230230
return graphql_main(self.to_internal(), query, root, vars, operation_name)

graphql/core/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from .executor import execute
2+
from .language import Source, parse
3+
4+
5+
def graphql(schema, request='', root=None, vars=None, operation_name=None):
6+
source = Source(request, 'GraphQL request')
7+
ast = parse(source)
8+
# TODO: validate document
9+
return execute(
10+
schema,
11+
root or object(),
12+
ast,
13+
vars or {},
14+
operation_name
15+
)
File renamed without changes.

graphql/core/executor/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .executor import execute, format_error # noqa

graphql/executor/executor.py renamed to graphql/core/executor/executor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
22
import collections
33
import re
4-
from graphql.error import GraphQLError, format_error
5-
from graphql.utils import type_from_ast, is_nullish
6-
from graphql.language import kinds as Kind
7-
from graphql.executor.values import get_variable_values, get_argument_values
8-
from graphql.type.definition import (
4+
from ..error import GraphQLError, format_error
5+
from ..utils import type_from_ast, is_nullish
6+
from ..language import kinds as Kind
7+
from .values import get_variable_values, get_argument_values
8+
from ..type.definition import (
99
GraphQLScalarType,
1010
GraphQLObjectType,
1111
GraphQLInterfaceType,
@@ -14,12 +14,12 @@
1414
GraphQLList,
1515
GraphQLNonNull,
1616
)
17-
from graphql.type.introspection import (
17+
from ..type.introspection import (
1818
SchemaMetaFieldDef,
1919
TypeMetaFieldDef,
2020
TypeNameMetaFieldDef,
2121
)
22-
from graphql.type.directives import (
22+
from ..type.directives import (
2323
GraphQLIncludeDirective,
2424
GraphQLSkipDirective,
2525
)

graphql/executor/values.py renamed to graphql/core/executor/values.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import collections
2-
from graphql.error import GraphQLError
3-
from graphql.language import Kind
4-
from graphql.type import (GraphQLNonNull, GraphQLList, GraphQLInputObjectType,
5-
GraphQLScalarType, GraphQLEnumType)
6-
from graphql.utils import type_from_ast, is_nullish
2+
from ..error import GraphQLError
3+
from ..language import Kind
4+
from ..type import (GraphQLNonNull, GraphQLList, GraphQLInputObjectType,
5+
GraphQLScalarType, GraphQLEnumType)
6+
from ..utils import type_from_ast, is_nullish
77

88
__all__ = ['get_variable_values', 'get_argument_values']
99

graphql/core/language/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# flake8: noqa
2+
from .location import get_location
3+
from . import kinds as Kind
4+
from .lexer import Lexer
5+
from .parser import parse
6+
from .source import Source
7+
from .error import LanguageError

graphql/language/error.py renamed to graphql/core/language/error.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from graphql.error import Error
2-
from graphql.language.location import get_location
1+
from ..error import Error
2+
from .location import get_location
33

44
__all__ = ['LanguageError']
55

File renamed without changes.

0 commit comments

Comments
 (0)