Skip to content

Commit 8e5c727

Browse files
committed
Add exeucte method on Schema object
1 parent 598f1b8 commit 8e5c727

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

graphql/api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from graphql import graphql as graphql_main
12
import graphql.type
23

34
__all__ = ['Schema']
@@ -224,3 +225,6 @@ def _define_type(self, cls, name, bases, dct, internal_type_builder):
224225

225226
def to_internal(self):
226227
return graphql.type.GraphQLSchema(self._query_root)
228+
229+
def execute(self, query, root=None, vars=None, operation_name=None):
230+
return graphql_main(self.to_internal(), query, root, vars, operation_name)

tests/contrib_django/test_django.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import django
22
from django.conf import settings
3-
from graphql import graphql
43
from graphql.contrib.django import DjangoSchema
54

65
settings.configure(
@@ -37,7 +36,7 @@ class QueryRoot(gql.QueryRoot):
3736
def humans(self, *args, **kwargs):
3837
return [Human(name='hi')]
3938

40-
result = graphql(gql.to_internal(), '''{
39+
result = gql.execute('''{
4140
humans { name }
4241
}''')
4342
assert not result.errors

tests/test_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pytest import raises
2-
from graphql import graphql
32
from graphql.api import Schema
43

54
gql = Schema()
@@ -73,7 +72,7 @@ class EpisodeEnum(gql.EnumType):
7372
class QueryRoot(gql.QueryRoot):
7473
episode = gql.Field(EpisodeEnum)
7574

76-
result = graphql(gql.to_internal(), '''{
75+
result = gql.execute('''{
7776
type: __type(name: "Episode") {
7877
name
7978
description
@@ -113,7 +112,7 @@ class QueryRoot(gql.QueryRoot):
113112
byNameWrapped = gql.Field(gql.List('Episode'))
114113
byInternalTypeWrapped = gql.Field(gql.List(gql.String))
115114

116-
result = graphql(gql.to_internal(), '''{
115+
result = gql.execute('''{
117116
type: __type(name: "QueryRoot") {
118117
name
119118
description
@@ -162,7 +161,7 @@ class QueryRoot(gql.QueryRoot):
162161
'byInternalTypeWrapped': gql.Argument(gql.List(gql.String)),
163162
})
164163

165-
result = graphql(gql.to_internal(), '''{
164+
result = gql.execute('''{
166165
type: __type(name: "QueryRoot") {
167166
fields {
168167
args {
@@ -224,7 +223,7 @@ class UnionType(gql.UnionType):
224223
class QueryRoot(gql.QueryRoot):
225224
union = gql.Field(UnionType)
226225

227-
result = graphql(gql.to_internal(), '''{
226+
result = gql.execute('''{
228227
type: __type(name: "Union") {
229228
kind
230229
name

0 commit comments

Comments
 (0)