def defines_a_mutation_schema(): BlogSchema = GraphQLSchema(query=BlogQuery, mutation=BlogMutation) assert BlogSchema.mutation_type == BlogMutation assert is_object_type(BlogMutation) write_mutation = BlogMutation.fields["writeArticle"] assert write_mutation.type == BlogArticle
def print_type(field) -> str: """Returns a string representation of a strawberry type""" if hasattr(field, "graphql_type"): field = field.graphql_type if is_object_type(field): return print_object(field) return original_print_type(field)
def defines_a_query_only_schema(): BlogSchema = GraphQLSchema(BlogQuery) assert BlogSchema.query_type == BlogQuery assert is_object_type(BlogQuery) article_field = BlogQuery.fields["article"] assert article_field.type == BlogArticle assert is_object_type(BlogArticle) blog_article_fields = BlogArticle.fields title_field = blog_article_fields["title"] assert title_field.type == GraphQLString author_field = blog_article_fields["author"] assert author_field.type == BlogAuthor assert is_object_type(BlogAuthor) recent_article_field = BlogAuthor.fields["recentArticle"] assert recent_article_field.type == BlogArticle feed_field = BlogQuery.fields["feed"] assert feed_field.type.of_type == BlogArticle
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_wrapped_object_type(): assert is_object_type(GraphQLList(ObjectType)) is False with raises(TypeError): assert_object_type(GraphQLList(ObjectType))
def returns_true_for_object_type(): assert is_object_type(ObjectType) is True assert_object_type(ObjectType)
def _print_type(field, schema: BaseSchema) -> str: if is_object_type(field): return _print_object(field, schema) return original_print_type(field)