Beispiel #1
0
def test_interface_type_resolver_may_be_set_using_setter(query_with_user_result):
    def resolve_result_type(*_):  # pylint: disable=unused-variable
        return "User"

    interface = InterfaceType("SearchResult")
    interface.set_type_resolver(resolve_result_type)

    schema = make_executable_schema(type_defs, [query_with_user_result, interface])
    result = graphql_sync(schema, "{ result { __typename } }")
    assert result.data == {"result": {"__typename": "User"}}
Beispiel #2
0
import copy
from datetime import datetime

from ariadne import UnionType, ScalarType, InterfaceType, ObjectType

from web.data import ingredients, suppliers, products

product_interface = InterfaceType('ProductInterface')
product_type = UnionType('Product')
ingredient_type = ObjectType('Ingredient')
supplier_type = ObjectType('Supplier')

datetime_scalar = ScalarType('Datetime')


@datetime_scalar.serializer
def serialize_datetime_scalar(date):
    return date.isoformat()


@datetime_scalar.value_parser
def parse_datetime_scalar(date):
    return datetime.fromisoformat(date)


@product_type.type_resolver
def resolve_product_type(obj, *_):
    if 'hasFilling' in obj:
        return 'Cake'
    return 'Beverage'
Beispiel #3
0
def createInterface(name):
    t = InterfaceType(name)
    registered_types.append(t)
    return t
Beispiel #4
0
 def __init__(self, name, type_resolver):
     resolver = InterfaceType(name, type_resolver)
     super().__init__(resolver)
Beispiel #5
0
from ariadne import QueryType, ObjectType, EnumType, MutationType, \
    InterfaceType, UnionType
from random import randint
from models import Skill, Person
from data import session
from datetime import datetime
from uuid import uuid4

# Type definitions
query = QueryType()
mutation = MutationType()
person = InterfaceType("Person")
skill = ObjectType("Skill")
# person = ObjectType("Person")
eye_color = EnumType(
    "EyeColor",
    {
        'BLUE': 'blue',
        'GREEN': 'green',
        'BROWN': 'brown',
        'BLACK': 'black',
    },
)
global_search = UnionType("GlobalSearch")


def create_persons(info, input):
    friends = []
    skills = []
    if 'friends' in input:
        person_ids = input.pop('friends')
Beispiel #6
0
def test_interface_type_resolver_may_be_set_on_initialization(query_with_user_result):
    interface = InterfaceType("SearchResult", type_resolver=lambda *_: "User")
    schema = make_executable_schema(type_defs, [query_with_user_result, interface])
    result = graphql_sync(schema, "{ result { __typename } }")
    assert result.data == {"result": {"__typename": "User"}}
Beispiel #7
0
def test_attempt_to_bind_interface_to_invalid_type_raises_error(schema):
    interface = InterfaceType("Query")
    with pytest.raises(ValueError):
        interface.bind_to_schema(schema)
Beispiel #8
0
def test_attempt_to_bind_interface_to_undefined_type_raises_error(schema):
    interface = InterfaceType("Test")
    with pytest.raises(ValueError):
        interface.bind_to_schema(schema)
Beispiel #9
0
def interface():
    return InterfaceType("SearchResult", type_resolver=resolve_result_type)
from ariadne import InterfaceType


relay_node = InterfaceType("Node")


@relay_node.type_resolver
def resolve_relay_node_type(obj, *_):
    return type(obj).__name__
Beispiel #11
0
from ariadne import InterfaceType, ObjectType, QueryType

waffle_type = ObjectType("Waffle")
waffle_flag_type = ObjectType("WaffleFlag")
waffle_switch_type = ObjectType("WaffleSwitch")
waffle_sample_type = ObjectType("WaffleSample")
waffle_item_interface = InterfaceType("WaffleItem")
query = QueryType()


def resolve_waffle_type(obj, *args):
    return f"Waffle{obj.__class__.__name__}"


waffle_item_interface.set_type_resolver(resolve_waffle_type)
Beispiel #12
0
        "NAME_ASC": "name",
    },
)

owner_union = UnionType("AccessmodOwner")


@owner_union.type_resolver
def resolve_accessmod_owner_type(obj, *_):
    if isinstance(obj, Team):
        return "Team"
    elif isinstance(obj, User):
        return "User"


ownership_interface = InterfaceType("AccessmodOwnership")


@ownership_interface.type_resolver
def resolve_ownership_type(obj, *_):
    if isinstance(obj, AccessibilityAnalysis):
        return "AccessmodAccessibilityAnalysis"
    elif isinstance(obj, GeographicCoverageAnalysis):
        return "AccessmodGeographicCoverageAnalysis"
    elif isinstance(obj, Project):
        return "AccessmodProject"
    elif isinstance(obj, Fileset):
        return "AccessmodFileset"


@project_object.field("authorizedActions")