|
26 | 26 | GraphQLSchema, |
27 | 27 | GraphQLString, |
28 | 28 | GraphQLType, |
| 29 | + GraphQLUnionType, |
| 30 | + SchemaMetaFieldDef, |
| 31 | + TypeMetaFieldDef, |
| 32 | + TypeNameMetaFieldDef, |
29 | 33 | specified_directives, |
30 | 34 | ) |
31 | 35 | from graphql.utilities import build_schema, lexicographic_sort_schema, print_schema |
@@ -293,6 +297,60 @@ def preserves_the_order_of_user_provided_types(): |
293 | 297 | copy_schema = GraphQLSchema(**schema.to_kwargs()) |
294 | 298 | assert list(copy_schema.type_map) == type_names |
295 | 299 |
|
| 300 | + def describe_get_field(): |
| 301 | + pet_type = GraphQLInterfaceType("Pet", {"name": GraphQLField(GraphQLString)}) |
| 302 | + cat_type = GraphQLObjectType( |
| 303 | + "Cat", {"name": GraphQLField(GraphQLString)}, [pet_type] |
| 304 | + ) |
| 305 | + dog_type = GraphQLObjectType( |
| 306 | + "Dog", {"name": GraphQLField(GraphQLString)}, [pet_type] |
| 307 | + ) |
| 308 | + cat_or_dog = GraphQLUnionType("CatOrDog", [cat_type, dog_type]) |
| 309 | + query_type = GraphQLObjectType("Query", {"catOrDog": GraphQLField(cat_or_dog)}) |
| 310 | + mutation_type = GraphQLObjectType("Mutation", {}) |
| 311 | + subscription_type = GraphQLObjectType("Subscription", {}) |
| 312 | + schema = GraphQLSchema(query_type, mutation_type, subscription_type) |
| 313 | + |
| 314 | + _get_field = schema.get_field |
| 315 | + |
| 316 | + def returns_known_field(): |
| 317 | + assert _get_field(pet_type, "name") == pet_type.fields["name"] |
| 318 | + assert _get_field(cat_type, "name") == cat_type.fields["name"] |
| 319 | + |
| 320 | + assert _get_field(query_type, "catOrDog") == query_type.fields["catOrDog"] |
| 321 | + |
| 322 | + def returns_none_for_unknown_fields(): |
| 323 | + assert _get_field(cat_or_dog, "name") is None |
| 324 | + |
| 325 | + assert _get_field(query_type, "unknown") is None |
| 326 | + assert _get_field(pet_type, "unknown") is None |
| 327 | + assert _get_field(cat_type, "unknown") is None |
| 328 | + assert _get_field(cat_or_dog, "unknown") is None |
| 329 | + |
| 330 | + def handles_introspection_fields(): |
| 331 | + assert _get_field(query_type, "__typename") == TypeNameMetaFieldDef |
| 332 | + assert _get_field(mutation_type, "__typename") == TypeNameMetaFieldDef |
| 333 | + assert _get_field(subscription_type, "__typename") == TypeNameMetaFieldDef |
| 334 | + |
| 335 | + assert _get_field(pet_type, "__typename") is TypeNameMetaFieldDef |
| 336 | + assert _get_field(cat_type, "__typename") is TypeNameMetaFieldDef |
| 337 | + assert _get_field(dog_type, "__typename") is TypeNameMetaFieldDef |
| 338 | + assert _get_field(cat_or_dog, "__typename") is TypeNameMetaFieldDef |
| 339 | + |
| 340 | + assert _get_field(query_type, "__type") is TypeMetaFieldDef |
| 341 | + assert _get_field(query_type, "__schema") is SchemaMetaFieldDef |
| 342 | + |
| 343 | + def returns_non_for_introspection_fields_in_wrong_location(): |
| 344 | + assert _get_field(pet_type, "__type") is None |
| 345 | + assert _get_field(dog_type, "__type") is None |
| 346 | + assert _get_field(mutation_type, "__type") is None |
| 347 | + assert _get_field(subscription_type, "__type") is None |
| 348 | + |
| 349 | + assert _get_field(pet_type, "__schema") is None |
| 350 | + assert _get_field(dog_type, "__schema") is None |
| 351 | + assert _get_field(mutation_type, "__schema") is None |
| 352 | + assert _get_field(subscription_type, "__schema") is None |
| 353 | + |
296 | 354 | def describe_validity(): |
297 | 355 | def describe_when_not_assumed_valid(): |
298 | 356 | def configures_the_schema_to_still_needing_validation(): |
|
0 commit comments