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
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
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
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
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)
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)
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
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
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
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
# 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
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)