def builds_a_schema_with_an_enum(): food_enum = GraphQLEnumType( "Food", { "VEGETABLES": GraphQLEnumValue( 1, description="Foods that are vegetables." ), "FRUITS": GraphQLEnumValue(2, description="Foods that are fruits."), "OILS": GraphQLEnumValue(3, description="Foods that are oils."), "DAIRY": GraphQLEnumValue(4, description="Foods that are dairy."), "MEAT": GraphQLEnumValue(5, description="Foods that are meat."), }, description="Varieties of food stuffs", ) schema = GraphQLSchema( GraphQLObjectType( "EnumFields", { "food": GraphQLField( food_enum, args={ "kind": GraphQLArgument( food_enum, description="what kind of food?" ) }, description="Repeats the arg you give it", ) }, ) ) introspection = introspection_from_schema(schema) client_schema = build_client_schema(introspection) second_introspection = introspection_from_schema(client_schema) hack_to_remove_standard_types(second_introspection) hack_to_remove_standard_types(introspection) assert second_introspection == introspection client_food_enum = client_schema.get_type("Food") # It's also an Enum type on the client. assert is_enum_type(client_food_enum) values = client_food_enum.values descriptions = {name: value.description for name, value in values.items()} assert descriptions == { "VEGETABLES": "Foods that are vegetables.", "FRUITS": "Foods that are fruits.", "OILS": "Foods that are oils.", "DAIRY": "Foods that are dairy.", "MEAT": "Foods that are meat.", } values = values.values() assert all(value.value is None for value in values) assert all(value.is_deprecated is False for value in values) assert all(value.deprecation_reason is None for value in values) assert all(value.ast_node is None for value in values)
def print_type(type_: GraphQLNamedType) -> str: if is_scalar_type(type_): type_ = cast(GraphQLScalarType, type_) return print_scalar(type_) if is_object_type(type_): type_ = cast(GraphQLObjectType, type_) return print_object(type_) if is_interface_type(type_): type_ = cast(GraphQLInterfaceType, type_) return print_interface(type_) if is_union_type(type_): type_ = cast(GraphQLUnionType, type_) return print_union(type_) if is_enum_type(type_): type_ = cast(GraphQLEnumType, type_) return print_enum(type_) if is_input_object_type(type_): type_ = cast(GraphQLInputObjectType, type_) return print_input_object(type_) # Not reachable. All possible types have been considered. raise TypeError(f"Unexpected type: '{inspect(type_)}'.") # pragma: no cover
def returns_false_for_non_enum_type(): assert is_enum_type(ScalarType) is False with raises(TypeError): assert_enum_type(ScalarType)
def returns_false_for_wrapped_enum_type(): assert is_enum_type(GraphQLList(EnumType)) is False with raises(TypeError): assert_enum_type(GraphQLList(EnumType))
def returns_true_for_enum_type(): assert is_enum_type(EnumType) is True assert_enum_type(EnumType)