示例#1
0
def test_schema_register():
    schema = Schema(name='My own schema')

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    assert schema.get_type('MyType') == MyType
示例#2
0
def test_schema_introspect():
    schema = Schema(name='My own schema')

    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    introspection = schema.introspect()
    assert '__schema' in introspection
示例#3
0
def test_schema_register():
    schema = Schema(name="My own schema")

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: "Dog")

    schema.query = MyType

    assert schema.get_type("MyType") == MyType
示例#4
0
def test_schema_introspect():
    schema = Schema(name="My own schema")

    class MyType(ObjectType):
        type = String(resolver=lambda *_: "Dog")

    schema.query = MyType

    introspection = schema.introspect()
    assert "__schema" in introspection
示例#5
0
def test_schema_introspect():
    schema = Schema(name='My own schema')

    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    introspection = schema.introspect()
    assert '__schema' in introspection
示例#6
0
def test_schema_register():
    schema = Schema(name='My own schema')

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    assert schema.get_type('MyType') == MyType
示例#7
0
def test_lazytype():
    schema = Schema(name='My own schema')

    t = LazyType('MyType')

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    assert schema.T(t) == schema.T(MyType)
示例#8
0
def test_lazytype():
    schema = Schema(name="My own schema")

    t = LazyType("MyType")

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: "Dog")

    schema.query = MyType

    assert schema.T(t) == schema.T(MyType)
示例#9
0
def test_lazytype():
    schema = Schema(name='My own schema')

    t = LazyType('MyType')

    @schema.register
    class MyType(ObjectType):
        type = String(resolver=lambda *_: 'Dog')

    schema.query = MyType

    assert schema.T(t) == schema.T(MyType)
示例#10
0
def test_auto_camelcase_off():
    schema = Schema(name='My own schema', auto_camelcase=False)

    class Query(ObjectType):
        test_field = String(resolver=lambda *_: 'Dog')

    schema.query = Query

    query = "query {test_field}"
    expected = {"test_field": "Dog"}

    result = graphql(schema.schema, query, root_value=Query(object()))
    assert not result.errors
    assert result.data == expected
示例#11
0
def test_auto_camelcase_off():
    schema = Schema(name="My own schema", auto_camelcase=False)

    class Query(ObjectType):
        test_field = String(resolver=lambda *_: "Dog")

    schema.query = Query

    query = "query {test_field}"
    expected = {"test_field": "Dog"}

    result = graphql(schema.schema, query, root_value=Query(object()))
    assert not result.errors
    assert result.data == expected
示例#12
0
class Human(Character):
    friends = List(Character)
    pet = Field(Pet)

    def resolve_name(self, *args):
        return 'Peter'

    def resolve_friend(self, *args):
        return Human(object())

    def resolve_pet(self, *args):
        return Pet(object())


schema.query = Human


def test_get_registered_type():
    assert schema.get_type('Character') == Character


def test_get_unregistered_type():
    with raises(Exception) as excinfo:
        schema.get_type('NON_EXISTENT_MODEL')
    assert 'not found' in str(excinfo.value)


def test_schema_query():
    assert schema.query == Human
示例#13
0
class Human(Character):
    friends = List(Character)
    pet = Field(Pet)

    def resolve_name(self, *args):
        return "Peter"

    def resolve_friend(self, *args):
        return Human(object())

    def resolve_pet(self, *args):
        return Pet(object())


schema.query = Human


def test_get_registered_type():
    assert schema.get_type("Character") == Character


def test_get_unregistered_type():
    with raises(Exception) as excinfo:
        schema.get_type("NON_EXISTENT_MODEL")
    assert "not found" in str(excinfo.value)


def test_schema_query():
    assert schema.query == Human
示例#14
0
# external imports
from graphene import ObjectType, Schema, resolve_only_args, List, String
# local imports
from .query import Query


# create the schema based on the query object
schema = Schema(name='Product Schema', auto_camelcase=False)
schema.query = Query
示例#15
0
from graphene import ObjectType, Schema
from graphene.relay import NodeField
from graphene.contrib.sqlalchemy import SQLAlchemyNode, \
    SQLAlchemyConnectionField

from test_graphene import models

schema = Schema()


@schema.register
class Note(SQLAlchemyNode):
    class Meta:
        model = models.Note


class Query(ObjectType):
    node = NodeField()
    all_notes = SQLAlchemyConnectionField(Note)


schema.query = Query

if __name__ == "__main__":
    import sys
    import json
    if len(sys.argv) > 1 and sys.argv[1] == "--json":
        print(json.dumps(schema.introspect(), indent=2))
    else:
        print(schema)