|
7 | 7 | from ..field import Field |
8 | 8 | from ..objecttype import ObjectType |
9 | 9 | from ..scalars import String |
10 | | -from ..schema import Schema, UnforgivingExecutionContext |
| 10 | +from ..schema import Schema |
11 | 11 |
|
12 | 12 |
|
13 | 13 | class MyOtherType(ObjectType): |
@@ -69,120 +69,3 @@ def test_schema_requires_query_type(): |
69 | 69 | assert len(result.errors) == 1 |
70 | 70 | error = result.errors[0] |
71 | 71 | assert error.message == "Query root type must be provided." |
72 | | - |
73 | | - |
74 | | -class TestUnforgivingExecutionContext: |
75 | | - @fixture |
76 | | - def schema(self): |
77 | | - class ErrorFieldsMixin: |
78 | | - sanity_field = String() |
79 | | - expected_error_field = String() |
80 | | - unexpected_value_error_field = String() |
81 | | - unexpected_type_error_field = String() |
82 | | - unexpected_attribute_error_field = String() |
83 | | - unexpected_key_error_field = String() |
84 | | - |
85 | | - @staticmethod |
86 | | - def resolve_sanity_field(obj, info): |
87 | | - return "not an error" |
88 | | - |
89 | | - @staticmethod |
90 | | - def resolve_expected_error_field(obj, info): |
91 | | - raise GraphQLError("expected error") |
92 | | - |
93 | | - @staticmethod |
94 | | - def resolve_unexpected_value_error_field(obj, info): |
95 | | - raise ValueError("unexpected error") |
96 | | - |
97 | | - @staticmethod |
98 | | - def resolve_unexpected_type_error_field(obj, info): |
99 | | - raise TypeError("unexpected error") |
100 | | - |
101 | | - @staticmethod |
102 | | - def resolve_unexpected_attribute_error_field(obj, info): |
103 | | - raise AttributeError("unexpected error") |
104 | | - |
105 | | - @staticmethod |
106 | | - def resolve_unexpected_key_error_field(obj, info): |
107 | | - return {}["fails"] |
108 | | - |
109 | | - class NestedObject(ErrorFieldsMixin, ObjectType): |
110 | | - pass |
111 | | - |
112 | | - class MyQuery(ErrorFieldsMixin, ObjectType): |
113 | | - nested_object = Field(NestedObject) |
114 | | - nested_object_error = Field(NestedObject) |
115 | | - |
116 | | - @staticmethod |
117 | | - def resolve_nested_object(obj, info): |
118 | | - return object() |
119 | | - |
120 | | - @staticmethod |
121 | | - def resolve_nested_object_error(obj, info): |
122 | | - raise TypeError() |
123 | | - |
124 | | - schema = Schema(query=MyQuery) |
125 | | - return schema |
126 | | - |
127 | | - def test_sanity_check(self, schema): |
128 | | - # this should pass with no errors (sanity check) |
129 | | - result = schema.execute( |
130 | | - "query { sanityField }", |
131 | | - execution_context_class=UnforgivingExecutionContext, |
132 | | - ) |
133 | | - assert not result.errors |
134 | | - assert result.data == {"sanityField": "not an error"} |
135 | | - |
136 | | - def test_nested_sanity_check(self, schema): |
137 | | - # this should pass with no errors (sanity check) |
138 | | - result = schema.execute( |
139 | | - r"query { nestedObject { sanityField } }", |
140 | | - execution_context_class=UnforgivingExecutionContext, |
141 | | - ) |
142 | | - assert not result.errors |
143 | | - assert result.data == {"nestedObject": {"sanityField": "not an error"}} |
144 | | - |
145 | | - def test_graphql_error(self, schema): |
146 | | - result = schema.execute( |
147 | | - "query { expectedErrorField }", |
148 | | - execution_context_class=UnforgivingExecutionContext, |
149 | | - ) |
150 | | - assert len(result.errors) == 1 |
151 | | - assert result.errors[0].message == "expected error" |
152 | | - assert result.data == {"expectedErrorField": None} |
153 | | - |
154 | | - def test_nested_graphql_error(self, schema): |
155 | | - result = schema.execute( |
156 | | - r"query { nestedObject { expectedErrorField } }", |
157 | | - execution_context_class=UnforgivingExecutionContext, |
158 | | - ) |
159 | | - assert len(result.errors) == 1 |
160 | | - assert result.errors[0].message == "expected error" |
161 | | - assert result.data == {"nestedObject": {"expectedErrorField": None}} |
162 | | - |
163 | | - @mark.parametrize( |
164 | | - "field,exception", |
165 | | - [ |
166 | | - ("unexpectedValueErrorField", ValueError), |
167 | | - ("unexpectedTypeErrorField", TypeError), |
168 | | - ("unexpectedAttributeErrorField", AttributeError), |
169 | | - ("unexpectedKeyErrorField", KeyError), |
170 | | - ("nestedObject { unexpectedValueErrorField }", ValueError), |
171 | | - ("nestedObject { unexpectedTypeErrorField }", TypeError), |
172 | | - ("nestedObject { unexpectedAttributeErrorField }", AttributeError), |
173 | | - ("nestedObject { unexpectedKeyErrorField }", KeyError), |
174 | | - ("nestedObjectError { __typename }", TypeError), |
175 | | - ], |
176 | | - ) |
177 | | - def test_unexpected_error(self, field, exception, schema): |
178 | | - # FIXME: tests are failing currently because no exception |
179 | | - # is being raised below. Instead, the errors are being propagated |
180 | | - # to the `errors` array of the response. If this is intended |
181 | | - # behaviour, we need to check if the error exists in the `errors` |
182 | | - # array rather than checking if an exception is raised. |
183 | | - with raises(exception): |
184 | | - # no result, but the exception should be propagated |
185 | | - schema.execute( |
186 | | - f"query {{ {field} }}", |
187 | | - execution_context_class=UnforgivingExecutionContext, |
188 | | - ) |
0 commit comments