mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
8e7d76bbce
* v3.0 - remove Python 2.x from build (#983) * Change travis to only compile for p3.6+ * Changed tox to only run Python 3.6+ * Changed library classifiers to reflect support in Python 3.6+ * Changed version to 3.0.0 development In [15]: get_version((3, 0, 0, "alpha", 0)) Out[15]: '3.0.dev20190601212304' * Reorganize Tests (#985) We no longer need a dedicated folder for Python3.6+ tests We no longer need to check six.PY3 in tests * Upgrade black to 19.3b0 (#987) * Remove six dependency (#986) * No one is using func_name * Remove six simple usages * Remove six requirement * Remove `six.with_metaclass` calls * pytest-asyncio should be a regular dependency now with Py3 move * Change dependency to graphql-core-next (#988) * Changed dependencies to core-next * Converted Scalars * ResolveInfo name change * Ignore .venv * Make Schema compatible with GraphQL-core-next * Ignore more venv names and mypy and pytest caches * Remove print statements for debugging in schema test * core-next now provides out_type and out_name * Adapt date and time scalar types to core-next * Ignore the non-standard result.invalid flag * Results are named tuples in core-next (immutable) * Enum values are returned as dict in core-next * Fix mutation tests with promises * Make all 345 tests pass with graphql-core-next * Remove the compat module which was only needed for older Py version * Remove object as base class (not needed in Py 3) * We can assume that dicts are ordered in Py 3.6+ * Make use of the fact that dicts are iterable * Use consistent style of importing from pytest * Restore compatibility with graphql-relay-py v3 Add adpaters for the PageInfo and Connection args. * Avoid various deprecation warnings * Use graphql-core 3 instead of graphql-core-next * Update dependencies, reformat changes with black * Update graphene/relay/connection.py Co-Authored-By: Jonathan Kim <jkimbo@gmail.com> * Run black on setup.py * Remove trailing whitespace
179 lines
4.9 KiB
Python
179 lines
4.9 KiB
Python
import datetime
|
|
import graphene
|
|
from graphene import relay
|
|
from graphene.types.resolver import dict_resolver
|
|
|
|
from ..deduplicator import deflate
|
|
|
|
|
|
def test_does_not_modify_object_without_typename_and_id():
|
|
response = {"foo": "bar"}
|
|
|
|
deflated_response = deflate(response)
|
|
assert deflated_response == {"foo": "bar"}
|
|
|
|
|
|
def test_does_not_modify_first_instance_of_an_object():
|
|
response = {
|
|
"data": [
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
]
|
|
}
|
|
|
|
deflated_response = deflate(response)
|
|
|
|
assert deflated_response == {
|
|
"data": [
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
{"__typename": "foo", "id": 1},
|
|
]
|
|
}
|
|
|
|
|
|
def test_does_not_modify_first_instance_of_an_object_nested():
|
|
response = {
|
|
"data": [
|
|
{
|
|
"__typename": "foo",
|
|
"bar1": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"bar2": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"id": 1,
|
|
},
|
|
{
|
|
"__typename": "foo",
|
|
"bar1": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"bar2": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"id": 2,
|
|
},
|
|
]
|
|
}
|
|
|
|
deflated_response = deflate(response)
|
|
|
|
assert deflated_response == {
|
|
"data": [
|
|
{
|
|
"__typename": "foo",
|
|
"bar1": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"bar2": {"__typename": "bar", "id": 1, "name": "bar"},
|
|
"id": 1,
|
|
},
|
|
{
|
|
"__typename": "foo",
|
|
"bar1": {"__typename": "bar", "id": 1},
|
|
"bar2": {"__typename": "bar", "id": 1},
|
|
"id": 2,
|
|
},
|
|
]
|
|
}
|
|
|
|
|
|
def test_does_not_modify_input():
|
|
response = {
|
|
"data": [
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
]
|
|
}
|
|
|
|
deflate(response)
|
|
|
|
assert response == {
|
|
"data": [
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
{"__typename": "foo", "id": 1, "name": "foo"},
|
|
]
|
|
}
|
|
|
|
|
|
TEST_DATA = {
|
|
"events": [
|
|
{"id": "568", "date": datetime.date(2017, 5, 19), "movie": "1198359"},
|
|
{"id": "234", "date": datetime.date(2017, 5, 20), "movie": "1198359"},
|
|
],
|
|
"movies": {
|
|
"1198359": {
|
|
"name": "King Arthur: Legend of the Sword",
|
|
"synopsis": (
|
|
"When the child Arthur's father is murdered, Vortigern, "
|
|
"Arthur's uncle, seizes the crown. Robbed of his birthright and "
|
|
"with no idea who he truly is..."
|
|
),
|
|
}
|
|
},
|
|
}
|
|
|
|
|
|
def test_example_end_to_end():
|
|
class Movie(graphene.ObjectType):
|
|
class Meta:
|
|
interfaces = (relay.Node,)
|
|
default_resolver = dict_resolver
|
|
|
|
name = graphene.String(required=True)
|
|
synopsis = graphene.String(required=True)
|
|
|
|
class Event(graphene.ObjectType):
|
|
class Meta:
|
|
interfaces = (relay.Node,)
|
|
default_resolver = dict_resolver
|
|
|
|
movie = graphene.Field(Movie, required=True)
|
|
date = graphene.types.datetime.Date(required=True)
|
|
|
|
def resolve_movie(event, info):
|
|
return TEST_DATA["movies"][event["movie"]]
|
|
|
|
class Query(graphene.ObjectType):
|
|
events = graphene.List(graphene.NonNull(Event), required=True)
|
|
|
|
def resolve_events(_, info):
|
|
return TEST_DATA["events"]
|
|
|
|
schema = graphene.Schema(query=Query)
|
|
query = """\
|
|
{
|
|
events {
|
|
__typename
|
|
id
|
|
date
|
|
movie {
|
|
__typename
|
|
id
|
|
name
|
|
synopsis
|
|
}
|
|
}
|
|
}
|
|
"""
|
|
result = schema.execute(query)
|
|
assert not result.errors
|
|
|
|
data = deflate(result.data)
|
|
assert data == {
|
|
"events": [
|
|
{
|
|
"__typename": "Event",
|
|
"id": "RXZlbnQ6NTY4",
|
|
"date": "2017-05-19",
|
|
"movie": {
|
|
"__typename": "Movie",
|
|
"id": "TW92aWU6Tm9uZQ==",
|
|
"name": "King Arthur: Legend of the Sword",
|
|
"synopsis": (
|
|
"When the child Arthur's father is murdered, Vortigern, "
|
|
"Arthur's uncle, seizes the crown. Robbed of his birthright and "
|
|
"with no idea who he truly is..."
|
|
),
|
|
},
|
|
},
|
|
{
|
|
"__typename": "Event",
|
|
"id": "RXZlbnQ6MjM0",
|
|
"date": "2017-05-20",
|
|
"movie": {"__typename": "Movie", "id": "TW92aWU6Tm9uZQ=="},
|
|
},
|
|
]
|
|
}
|