prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Argument 'code' has invalid value "ABC"
  I think there is a bug when using both literal and variable values with a custom scalar.
  
  ```python
  from ariadne import ScalarType
  
  testscalar = ScalarType('TestScalar')
  
  @testscalar.serializer
  def serializer(value):
      return value.upper()
  
  
  @testscalar.value_parser
  def value_parser(value):
      if value:
          return serializer(value)
  
  
  @testscalar.literal_parser
  def literal_parser(ast):
      value = str(ast.value)
      return value_parser(value)
  ```
  
  If you then make the following query:
  ```graphql
  query($code: TestScalar) {
    test1: testType(code: $code) {
      id
    }
    test2: testType(code: "ABC") {
      id
    }
  }
  ```
   This error is returned: Argument 'code' has invalid value "ABC"
  
  If you don't pass variables and only use "literal" values it works. Same for if you only pass variables it works fine.
  
  If you don't set up a resolver for "testType" then no error is returned.
  
  Not sure what is happening but I think this is a bug. If not, does anyone know why this is happening?
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `ariadne/scalars.py`
  Content:
  ```
  1 from typing import Optional, cast
  2 
  3 from graphql.language.ast import (
  4     BooleanValueNode,
  5     FloatValueNode,
  6     IntValueNode,
  7     StringValueNode,
  8 )
  9 from graphql.type import (
  10     GraphQLNamedType,
  11     GraphQLScalarLiteralParser,
  12     GraphQLScalarSerializer,
  13     GraphQLScalarType,
  14     GraphQLScalarValueParser,
  15     GraphQLSchema,
  16 )
  17 from graphql.utilities import value_from_ast_untyped
  18 
  19 from .types import SchemaBindable
  20 
  21 
  22 class ScalarType(SchemaBindable):
  23     _serialize: Optional[GraphQLScalarSerializer]
  24     _parse_value: Optional[GraphQLScalarValueParser]
  25     _parse_literal: Optional[GraphQLScalarLiteralParser]
  26 
  27     def __init__(
  28         self,
  29         name: str,
  30         *,
  31         serializer: GraphQLScalarSerializer = None,
  32         value_parser: GraphQLScalarValueParser = None,
  33         literal_parser: GraphQLScalarLiteralParser = None,
  34     ) -> None:
  35         self.name = name
  36         self._serialize = serializer
  37         self._parse_value = value_parser
  38         self._parse_literal = literal_parser
  39 
  40     def set_serializer(self, f: GraphQLScalarSerializer) -> GraphQLScalarSerializer:
  41         self._serialize = f
  42         return f
  43 
  44     def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValueParser:
  45         self._parse_value = f
  46         if not self._parse_literal:
  47             self._parse_literal = create_default_literal_parser(f)
  48         return f
  49 
  50     def set_literal_parser(
  51         self, f: GraphQLScalarLiteralParser
  52     ) -> GraphQLScalarLiteralParser:
  53         self._parse_literal = f
  54         return f
  55 
  56     # Alias above setters for consistent decorator API
  57     serializer = set_serializer
  58     value_parser = set_value_parser
  59     literal_parser = set_literal_parser
  60 
  61     def bind_to_schema(self, schema: GraphQLSchema) -> None:
  62         graphql_type = schema.type_map.get(self.name)
  63         self.validate_graphql_type(graphql_type)
  64         graphql_type = cast(GraphQLScalarType, graphql_type)
  65 
  66         if self._serialize:
  67             # See mypy bug https://github.com/python/mypy/issues/2427
  68             graphql_type.serialize = self._serialize  # type: ignore
  69         if self._parse_value:
  70             graphql_type.parse_value = self._parse_value  # type: ignore
  71         if self._parse_literal:
  72             graphql_type.parse_literal = self._parse_literal  # type: ignore
  73 
  74     def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:
  75         if not graphql_type:
  76             raise ValueError("Scalar %s is not defined in the schema" % self.name)
  77         if not isinstance(graphql_type, GraphQLScalarType):
  78             raise ValueError(
  79                 "%s is defined in the schema, but it is instance of %s (expected %s)"
  80                 % (self.name, type(graphql_type).__name__, GraphQLScalarType.__name__)
  81             )
  82 
  83 
  84 SCALAR_AST_NODES = (BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode)
  85 
  86 
  87 def create_default_literal_parser(
  88     value_parser: GraphQLScalarValueParser,
  89 ) -> GraphQLScalarLiteralParser:
  90     def default_literal_parser(ast):
  91         return value_parser(value_from_ast_untyped(ast))
  92 
  93     return default_literal_parser
  94
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/ariadne/scalars.py b/ariadne/scalars.py
  --- a/ariadne/scalars.py
  +++ b/ariadne/scalars.py
  @@ -1,11 +1,5 @@
   from typing import Optional, cast
   
  -from graphql.language.ast import (
  -    BooleanValueNode,
  -    FloatValueNode,
  -    IntValueNode,
  -    StringValueNode,
  -)
   from graphql.type import (
       GraphQLNamedType,
       GraphQLScalarLiteralParser,
  @@ -14,7 +8,6 @@
       GraphQLScalarValueParser,
       GraphQLSchema,
   )
  -from graphql.utilities import value_from_ast_untyped
   
   from .types import SchemaBindable
   
  @@ -43,8 +36,6 @@
   
       def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValueParser:
           self._parse_value = f
  -        if not self._parse_literal:
  -            self._parse_literal = create_default_literal_parser(f)
           return f
   
       def set_literal_parser(
  @@ -79,15 +70,3 @@
                   "%s is defined in the schema, but it is instance of %s (expected %s)"
                   % (self.name, type(graphql_type).__name__, GraphQLScalarType.__name__)
               )
  -
  -
  -SCALAR_AST_NODES = (BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode)
  -
  -
  -def create_default_literal_parser(
  -    value_parser: GraphQLScalarValueParser,
  -) -> GraphQLScalarLiteralParser:
  -    def default_literal_parser(ast):
  -        return value_parser(value_from_ast_untyped(ast))
  -
  -    return default_literal_parser
  
verification_info: {"golden_diff": "diff --git a/ariadne/scalars.py b/ariadne/scalars.py\n--- a/ariadne/scalars.py\n+++ b/ariadne/scalars.py\n@@ -1,11 +1,5 @@\n from typing import Optional, cast\n \n-from graphql.language.ast import (\n-    BooleanValueNode,\n-    FloatValueNode,\n-    IntValueNode,\n-    StringValueNode,\n-)\n from graphql.type import (\n     GraphQLNamedType,\n     GraphQLScalarLiteralParser,\n@@ -14,7 +8,6 @@\n     GraphQLScalarValueParser,\n     GraphQLSchema,\n )\n-from graphql.utilities import value_from_ast_untyped\n \n from .types import SchemaBindable\n \n@@ -43,8 +36,6 @@\n \n     def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValueParser:\n         self._parse_value = f\n-        if not self._parse_literal:\n-            self._parse_literal = create_default_literal_parser(f)\n         return f\n \n     def set_literal_parser(\n@@ -79,15 +70,3 @@\n                 \"%s is defined in the schema, but it is instance of %s (expected %s)\"\n                 % (self.name, type(graphql_type).__name__, GraphQLScalarType.__name__)\n             )\n-\n-\n-SCALAR_AST_NODES = (BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode)\n-\n-\n-def create_default_literal_parser(\n-    value_parser: GraphQLScalarValueParser,\n-) -> GraphQLScalarLiteralParser:\n-    def default_literal_parser(ast):\n-        return value_parser(value_from_ast_untyped(ast))\n-\n-    return default_literal_parser\n", "issue": "Argument 'code' has invalid value \"ABC\"\nI think there is a bug when using both literal and variable values with a custom scalar.\r\n\r\n```python\r\nfrom ariadne import ScalarType\r\n\r\ntestscalar = ScalarType('TestScalar')\r\n\r\n@testscalar.serializer\r\ndef serializer(value):\r\n    return value.upper()\r\n\r\n\r\n@testscalar.value_parser\r\ndef value_parser(value):\r\n    if value:\r\n        return serializer(value)\r\n\r\n\r\n@testscalar.literal_parser\r\ndef literal_parser(ast):\r\n    value = str(ast.value)\r\n    return value_parser(value)\r\n```\r\n\r\nIf you then make the following query:\r\n```graphql\r\nquery($code: TestScalar) {\r\n  test1: testType(code: $code) {\r\n    id\r\n  }\r\n  test2: testType(code: \"ABC\") {\r\n    id\r\n  }\r\n}\r\n```\r\n This error is returned: Argument 'code' has invalid value \"ABC\"\r\n\r\nIf you don't pass variables and only use \"literal\" values it works. Same for if you only pass variables it works fine.\r\n\r\nIf you don't set up a resolver for \"testType\" then no error is returned.\r\n\r\nNot sure what is happening but I think this is a bug. If not, does anyone know why this is happening?\n", "before_files": [{"content": "from typing import Optional, cast\n\nfrom graphql.language.ast import (\n    BooleanValueNode,\n    FloatValueNode,\n    IntValueNode,\n    StringValueNode,\n)\nfrom graphql.type import (\n    GraphQLNamedType,\n    GraphQLScalarLiteralParser,\n    GraphQLScalarSerializer,\n    GraphQLScalarType,\n    GraphQLScalarValueParser,\n    GraphQLSchema,\n)\nfrom graphql.utilities import value_from_ast_untyped\n\nfrom .types import SchemaBindable\n\n\nclass ScalarType(SchemaBindable):\n    _serialize: Optional[GraphQLScalarSerializer]\n    _parse_value: Optional[GraphQLScalarValueParser]\n    _parse_literal: Optional[GraphQLScalarLiteralParser]\n\n    def __init__(\n        self,\n        name: str,\n        *,\n        serializer: GraphQLScalarSerializer = None,\n        value_parser: GraphQLScalarValueParser = None,\n        literal_parser: GraphQLScalarLiteralParser = None,\n    ) -> None:\n        self.name = name\n        self._serialize = serializer\n        self._parse_value = value_parser\n        self._parse_literal = literal_parser\n\n    def set_serializer(self, f: GraphQLScalarSerializer) -> GraphQLScalarSerializer:\n        self._serialize = f\n        return f\n\n    def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValueParser:\n        self._parse_value = f\n        if not self._parse_literal:\n            self._parse_literal = create_default_literal_parser(f)\n        return f\n\n    def set_literal_parser(\n        self, f: GraphQLScalarLiteralParser\n    ) -> GraphQLScalarLiteralParser:\n        self._parse_literal = f\n        return f\n\n    # Alias above setters for consistent decorator API\n    serializer = set_serializer\n    value_parser = set_value_parser\n    literal_parser = set_literal_parser\n\n    def bind_to_schema(self, schema: GraphQLSchema) -> None:\n        graphql_type = schema.type_map.get(self.name)\n        self.validate_graphql_type(graphql_type)\n        graphql_type = cast(GraphQLScalarType, graphql_type)\n\n        if self._serialize:\n            # See mypy bug https://github.com/python/mypy/issues/2427\n            graphql_type.serialize = self._serialize  # type: ignore\n        if self._parse_value:\n            graphql_type.parse_value = self._parse_value  # type: ignore\n        if self._parse_literal:\n            graphql_type.parse_literal = self._parse_literal  # type: ignore\n\n    def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:\n        if not graphql_type:\n            raise ValueError(\"Scalar %s is not defined in the schema\" % self.name)\n        if not isinstance(graphql_type, GraphQLScalarType):\n            raise ValueError(\n                \"%s is defined in the schema, but it is instance of %s (expected %s)\"\n                % (self.name, type(graphql_type).__name__, GraphQLScalarType.__name__)\n            )\n\n\nSCALAR_AST_NODES = (BooleanValueNode, FloatValueNode, IntValueNode, StringValueNode)\n\n\ndef create_default_literal_parser(\n    value_parser: GraphQLScalarValueParser,\n) -> GraphQLScalarLiteralParser:\n    def default_literal_parser(ast):\n        return value_parser(value_from_ast_untyped(ast))\n\n    return default_literal_parser\n", "path": "ariadne/scalars.py"}], "after_files": [{"content": "from typing import Optional, cast\n\nfrom graphql.type import (\n    GraphQLNamedType,\n    GraphQLScalarLiteralParser,\n    GraphQLScalarSerializer,\n    GraphQLScalarType,\n    GraphQLScalarValueParser,\n    GraphQLSchema,\n)\n\nfrom .types import SchemaBindable\n\n\nclass ScalarType(SchemaBindable):\n    _serialize: Optional[GraphQLScalarSerializer]\n    _parse_value: Optional[GraphQLScalarValueParser]\n    _parse_literal: Optional[GraphQLScalarLiteralParser]\n\n    def __init__(\n        self,\n        name: str,\n        *,\n        serializer: GraphQLScalarSerializer = None,\n        value_parser: GraphQLScalarValueParser = None,\n        literal_parser: GraphQLScalarLiteralParser = None,\n    ) -> None:\n        self.name = name\n        self._serialize = serializer\n        self._parse_value = value_parser\n        self._parse_literal = literal_parser\n\n    def set_serializer(self, f: GraphQLScalarSerializer) -> GraphQLScalarSerializer:\n        self._serialize = f\n        return f\n\n    def set_value_parser(self, f: GraphQLScalarValueParser) -> GraphQLScalarValueParser:\n        self._parse_value = f\n        return f\n\n    def set_literal_parser(\n        self, f: GraphQLScalarLiteralParser\n    ) -> GraphQLScalarLiteralParser:\n        self._parse_literal = f\n        return f\n\n    # Alias above setters for consistent decorator API\n    serializer = set_serializer\n    value_parser = set_value_parser\n    literal_parser = set_literal_parser\n\n    def bind_to_schema(self, schema: GraphQLSchema) -> None:\n        graphql_type = schema.type_map.get(self.name)\n        self.validate_graphql_type(graphql_type)\n        graphql_type = cast(GraphQLScalarType, graphql_type)\n\n        if self._serialize:\n            # See mypy bug https://github.com/python/mypy/issues/2427\n            graphql_type.serialize = self._serialize  # type: ignore\n        if self._parse_value:\n            graphql_type.parse_value = self._parse_value  # type: ignore\n        if self._parse_literal:\n            graphql_type.parse_literal = self._parse_literal  # type: ignore\n\n    def validate_graphql_type(self, graphql_type: Optional[GraphQLNamedType]) -> None:\n        if not graphql_type:\n            raise ValueError(\"Scalar %s is not defined in the schema\" % self.name)\n        if not isinstance(graphql_type, GraphQLScalarType):\n            raise ValueError(\n                \"%s is defined in the schema, but it is instance of %s (expected %s)\"\n                % (self.name, type(graphql_type).__name__, GraphQLScalarType.__name__)\n            )\n", "path": "ariadne/scalars.py"}]}