Repository: saleor/saleor

Issue:
Getting error when category has no background image
### Steps to reproduce the problem
1. Create category with no background image
2. Exec query
```
{
  category {
    backgroundImage {
      url
    }
  }
}
```
3. Get an error
```
{
  "errors": [
    {
      "message": "The 'background_image' attribute has no file associated with it.",
      "locations": [
        {
          "line": 6,
          "column": 7
        }
      ],
      "path": [
        "categories",
        "edges",
        1,
        "node",
        "backgroundImage",
        "url"
      ]
    }
  ]
}
```

### What I expected to happen
To successfully fetch category data.


Discussion:
Same situation should be checked for collections with no backgorund_image


Resolving patch:
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -296,6 +296,9 @@ class Meta:
         interfaces = [relay.Node]
         model = models.Collection
 
+    def resolve_background_image(self, info, **kwargs):
+        return self.background_image or None
+
     def resolve_products(self, info, **kwargs):
         user = info.context.user
         return products_with_details(
@@ -331,6 +334,9 @@ class Meta:
     def resolve_ancestors(self, info, **kwargs):
         return self.get_ancestors().distinct()
 
+    def resolve_background_image(self, info, **kwargs):
+        return self.background_image or None
+
     def resolve_children(self, info, **kwargs):
         return self.children.distinct()
 


Test patch:
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -1319,6 +1319,28 @@ def test_category_image_query(user_api_client, non_default_category):
     assert data['backgroundImage']['url'] == thumbnail_url
 
 
+def test_category_image_query_without_associated_file(
+        user_api_client, non_default_category):
+    category = non_default_category
+    category_id = graphene.Node.to_global_id('Category', category.pk)
+    query = """
+        query fetchCategory($id: ID!){
+            category(id: $id) {
+                name
+                backgroundImage {
+                   url
+                }
+            }
+        }
+    """
+    variables = {'id': category_id}
+    response = user_api_client.post_graphql(query, variables)
+    content = get_graphql_content(response)
+    data = content['data']['category']
+    assert data['name'] == category.name
+    assert data['backgroundImage'] is None
+
+
 def test_collection_image_query(user_api_client, collection):
     image_file, image_name = create_image()
     collection.background_image = image_file
@@ -1341,6 +1363,27 @@ def test_collection_image_query(user_api_client, collection):
     assert data['backgroundImage']['url'] == thumbnail_url
 
 
+def test_collection_image_query_without_associated_file(
+        user_api_client, collection):
+    collection_id = graphene.Node.to_global_id('Collection', collection.pk)
+    query = """
+        query fetchCollection($id: ID!){
+            collection(id: $id) {
+                name
+                backgroundImage {
+                   url
+                }
+            }
+        }
+    """
+    variables = {'id': collection_id}
+    response = user_api_client.post_graphql(query, variables)
+    content = get_graphql_content(response)
+    data = content['data']['collection']
+    assert data['name'] == collection.name
+    assert data['backgroundImage'] is None
+
+
 @pytest.mark.parametrize('product_price, variant_override, api_variant_price', [
     (100, None, 100),
     (100, 200, 200),