Пример #1
0
def test_attempt_bind_subscription_to_undefined_field_raises_error(schema):
    async def source(*_):
        yield "test"  # pragma: no cover

    subscription = SubscriptionType()
    subscription.set_source("fake", source)
    with pytest.raises(ValueError):
        subscription.bind_to_schema(schema)
Пример #2
0
def subscriptions():
    subscription = SubscriptionType()
    subscription.set_source("ping", ping_generator)
    subscription.set_source("resolverError", ping_generator)
    subscription.set_field("resolverError", resolve_error)
    subscription.set_source("sourceError", error_generator)
    subscription.set_source("testContext", test_context_generator)
    subscription.set_source("testRoot", test_root_generator)
    return subscription
Пример #3
0
def test_field_source_can_be_set_using_setter(schema):
    async def source(*_):
        yield "test"  # pragma: no cover

    subscription = SubscriptionType()
    subscription.set_source("message", source)
    subscription.bind_to_schema(schema)
    field = schema.type_map.get("Subscription").fields["message"]
    assert field.subscribe is source
Пример #4
0
    def start(self):
        query = QueryType()
        query.set_field('echo', self._echo_resolver())

        mutation = MutationType()
        mutation.set_field('createTable', self._create_table_resolver())
        mutation.set_field('addPlayer', self._add_player_resolver())
        mutation.set_field('takeAction', self._take_action_resolver())
        mutation.set_field('startGame', self._start_game_resolver())
        mutation.set_field('stopGame', self._stop_game_resolver())
        mutation.set_field('reset', self._reset_resolver())

        subscription = SubscriptionType()
        subscription.set_field('subscribe', self._subscribe_resolver())
        subscription.set_source('subscribe', self._subscribe_generator())

        resolvers = [query, mutation, subscription]

        executable_schema = make_executable_schema(self._schema_str, resolvers)
        self._app = GraphQL(executable_schema, debug=True)
Пример #5
0
type_defs = load_schema_from_path("saltapi/graphql/schema.graphql")

datetime_scalar = ScalarType("Datetime")
datetime_scalar.set_serializer(scalars.serialize_datetime)
datetime_scalar.set_value_parser(scalars.parse_datetime)

proposal_code_scalar = ScalarType("ProposalCode")
proposal_code_scalar.set_serializer(scalars.serialize_proposal_code)
proposal_code_scalar.set_value_parser(scalars.parse_proposal_code)

mutation = MutationType()
mutation.set_field("submitProposal", resolvers.resolve_submit_proposal)

subscription = SubscriptionType()
subscription.set_field("submissionProgress", resolvers.resolve_submission_progress)
subscription.set_source("submissionProgress", resolvers.submission_progress_generator)

schema = make_executable_schema(
    type_defs,
    datetime_scalar,
    proposal_code_scalar,
    mutation,
    subscription,
    directives={"permittedFor": PermittedForDirective},
)


# non-GraphQL routes


async def token(request: Request) -> Response: