prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ProductCreate weight mutation
  
  ![p1](https://user-images.githubusercontent.com/36409853/79555939-f2032000-80d2-11ea-88cc-5e1809e51ec5.PNG)
  ![p2](https://user-images.githubusercontent.com/36409853/79556174-4b6b4f00-80d3-11ea-96d7-f06ee76bf1ee.PNG)
  
  
  productCreate mutation
  
  I followed the "amount unit" as said in the comment, but returns a "'StringValue(value='10.00 kg')' value must be a float."
  Sorry just a beginner
  
  </issue>
  <code>
  [start of saleor/graphql/core/scalars.py]
  1 import decimal
  2 
  3 import graphene
  4 from measurement.measures import Weight
  5 
  6 from ...core.weight import convert_weight, get_default_weight_unit
  7 
  8 
  9 class Decimal(graphene.Float):
  10     """Custom Decimal implementation.
  11 
  12     Returns Decimal as a float in the API,
  13     parses float to the Decimal on the way back.
  14     """
  15 
  16     @staticmethod
  17     def parse_literal(node):
  18         try:
  19             return decimal.Decimal(node.value)
  20         except decimal.DecimalException:
  21             return None
  22 
  23     @staticmethod
  24     def parse_value(value):
  25         try:
  26             # Converting the float to str before parsing it to Decimal is
  27             # necessary to keep the decimal places as typed
  28             value = str(value)
  29             return decimal.Decimal(value)
  30         except decimal.DecimalException:
  31             return None
  32 
  33 
  34 class WeightScalar(graphene.Scalar):
  35     @staticmethod
  36     def parse_value(value):
  37         # Expects value to be a string "amount unit" separated by a single
  38         # space.
  39         try:
  40             value = decimal.Decimal(value)
  41         except decimal.DecimalException:
  42             return None
  43         default_unit = get_default_weight_unit()
  44         return Weight(**{default_unit: value})
  45 
  46     @staticmethod
  47     def serialize(weight):
  48         if isinstance(weight, Weight):
  49             default_unit = get_default_weight_unit()
  50             if weight.unit != default_unit:
  51                 weight = convert_weight(weight, default_unit)
  52             return str(weight)
  53         return None
  54 
  55     @staticmethod
  56     def parse_literal(node):
  57         return node
  58
  [end of saleor/graphql/core/scalars.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.py
  --- a/saleor/graphql/core/scalars.py
  +++ b/saleor/graphql/core/scalars.py
  @@ -1,6 +1,8 @@
   import decimal
   
   import graphene
  +from graphql.language import ast
  +from graphql.error import GraphQLError
   from measurement.measures import Weight
   
   from ...core.weight import convert_weight, get_default_weight_unit
  @@ -34,14 +36,14 @@
   class WeightScalar(graphene.Scalar):
       @staticmethod
       def parse_value(value):
  -        # Expects value to be a string "amount unit" separated by a single
  -        # space.
  -        try:
  -            value = decimal.Decimal(value)
  -        except decimal.DecimalException:
  -            return None
  -        default_unit = get_default_weight_unit()
  -        return Weight(**{default_unit: value})
  +        weight = None
  +        if isinstance(value, dict):
  +            weight = Weight(**{value["unit"]: value["value"]})
  +        else:
  +            weight = WeightScalar.parse_decimal(value)
  +        if not weight:
  +            raise GraphQLError(f"Unsupported value: {value}")
  +        return weight
   
       @staticmethod
       def serialize(weight):
  @@ -54,4 +56,35 @@
   
       @staticmethod
       def parse_literal(node):
  -        return node
  +        weight = None
  +        if isinstance(node, ast.ObjectValue):
  +            weight = WeightScalar.parse_literal_object(node)
  +        else:
  +            weight = WeightScalar.parse_decimal(node.value)
  +        if not weight:
  +            raise GraphQLError(f"Unsupported value: {node.value}")
  +        return weight
  +
  +    @staticmethod
  +    def parse_decimal(value):
  +        try:
  +            value = decimal.Decimal(value)
  +        except decimal.DecimalException:
  +            return None
  +        default_unit = get_default_weight_unit()
  +        return Weight(**{default_unit: value})
  +
  +    @staticmethod
  +    def parse_literal_object(node):
  +        value = 0
  +        unit = get_default_weight_unit()
  +
  +        for field in node.fields:
  +            if field.name.value == "value":
  +                try:
  +                    value = decimal.Decimal(field.value.value)
  +                except decimal.DecimalException:
  +                    raise GraphQLError(f"Unsupported value: {field.value.value}")
  +            if field.name.value == "unit":
  +                unit = field.value.value
  +        return Weight(**{unit: value})
  
verification_info: {"golden_diff": "diff --git a/saleor/graphql/core/scalars.py b/saleor/graphql/core/scalars.py\n--- a/saleor/graphql/core/scalars.py\n+++ b/saleor/graphql/core/scalars.py\n@@ -1,6 +1,8 @@\n import decimal\n \n import graphene\n+from graphql.language import ast\n+from graphql.error import GraphQLError\n from measurement.measures import Weight\n \n from ...core.weight import convert_weight, get_default_weight_unit\n@@ -34,14 +36,14 @@\n class WeightScalar(graphene.Scalar):\n     @staticmethod\n     def parse_value(value):\n-        # Expects value to be a string \"amount unit\" separated by a single\n-        # space.\n-        try:\n-            value = decimal.Decimal(value)\n-        except decimal.DecimalException:\n-            return None\n-        default_unit = get_default_weight_unit()\n-        return Weight(**{default_unit: value})\n+        weight = None\n+        if isinstance(value, dict):\n+            weight = Weight(**{value[\"unit\"]: value[\"value\"]})\n+        else:\n+            weight = WeightScalar.parse_decimal(value)\n+        if not weight:\n+            raise GraphQLError(f\"Unsupported value: {value}\")\n+        return weight\n \n     @staticmethod\n     def serialize(weight):\n@@ -54,4 +56,35 @@\n \n     @staticmethod\n     def parse_literal(node):\n-        return node\n+        weight = None\n+        if isinstance(node, ast.ObjectValue):\n+            weight = WeightScalar.parse_literal_object(node)\n+        else:\n+            weight = WeightScalar.parse_decimal(node.value)\n+        if not weight:\n+            raise GraphQLError(f\"Unsupported value: {node.value}\")\n+        return weight\n+\n+    @staticmethod\n+    def parse_decimal(value):\n+        try:\n+            value = decimal.Decimal(value)\n+        except decimal.DecimalException:\n+            return None\n+        default_unit = get_default_weight_unit()\n+        return Weight(**{default_unit: value})\n+\n+    @staticmethod\n+    def parse_literal_object(node):\n+        value = 0\n+        unit = get_default_weight_unit()\n+\n+        for field in node.fields:\n+            if field.name.value == \"value\":\n+                try:\n+                    value = decimal.Decimal(field.value.value)\n+                except decimal.DecimalException:\n+                    raise GraphQLError(f\"Unsupported value: {field.value.value}\")\n+            if field.name.value == \"unit\":\n+                unit = field.value.value\n+        return Weight(**{unit: value})\n", "issue": "ProductCreate weight mutation\n\r\n![p1](https://user-images.githubusercontent.com/36409853/79555939-f2032000-80d2-11ea-88cc-5e1809e51ec5.PNG)\r\n![p2](https://user-images.githubusercontent.com/36409853/79556174-4b6b4f00-80d3-11ea-96d7-f06ee76bf1ee.PNG)\r\n\r\n\r\nproductCreate mutation\r\n\r\nI followed the \"amount unit\" as said in the comment, but returns a \"'StringValue(value='10.00 kg')' value must be a float.\"\r\nSorry just a beginner\n", "before_files": [{"content": "import decimal\n\nimport graphene\nfrom measurement.measures import Weight\n\nfrom ...core.weight import convert_weight, get_default_weight_unit\n\n\nclass Decimal(graphene.Float):\n    \"\"\"Custom Decimal implementation.\n\n    Returns Decimal as a float in the API,\n    parses float to the Decimal on the way back.\n    \"\"\"\n\n    @staticmethod\n    def parse_literal(node):\n        try:\n            return decimal.Decimal(node.value)\n        except decimal.DecimalException:\n            return None\n\n    @staticmethod\n    def parse_value(value):\n        try:\n            # Converting the float to str before parsing it to Decimal is\n            # necessary to keep the decimal places as typed\n            value = str(value)\n            return decimal.Decimal(value)\n        except decimal.DecimalException:\n            return None\n\n\nclass WeightScalar(graphene.Scalar):\n    @staticmethod\n    def parse_value(value):\n        # Expects value to be a string \"amount unit\" separated by a single\n        # space.\n        try:\n            value = decimal.Decimal(value)\n        except decimal.DecimalException:\n            return None\n        default_unit = get_default_weight_unit()\n        return Weight(**{default_unit: value})\n\n    @staticmethod\n    def serialize(weight):\n        if isinstance(weight, Weight):\n            default_unit = get_default_weight_unit()\n            if weight.unit != default_unit:\n                weight = convert_weight(weight, default_unit)\n            return str(weight)\n        return None\n\n    @staticmethod\n    def parse_literal(node):\n        return node\n", "path": "saleor/graphql/core/scalars.py"}]}