codecov[bot]: # [Codecov](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=h1) Report
> Merging [#153](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=desc) into [master](https://codecov.io/gh/mirumee/ariadne/commit/aa3d994c27a740306edace41ce66842e6a8a02a3?src=pr&el=desc) will **increase** coverage by `0.1%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/mirumee/ariadne/pull/153/graphs/tree.svg?width=650&token=8GSRgVxHd7&height=150&src=pr)](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master     #153     +/-   ##
=========================================
+ Coverage   97.72%   97.82%   +0.1%     
=========================================
  Files          60       60             
  Lines        2018     2025      +7     
=========================================
+ Hits         1972     1981      +9     
+ Misses         46       44      -2
```


| [Impacted Files](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [ariadne/subscriptions.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS9zdWJzY3JpcHRpb25zLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [tests/test\_subscriptions.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9zdWJzY3JpcHRpb25zLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [ariadne/objects.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS9vYmplY3RzLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [tests/test\_objects.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9vYmplY3RzLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [ariadne/wsgi.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS93c2dpLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [ariadne/scalars.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS9zY2FsYXJzLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [ariadne/interfaces.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS9pbnRlcmZhY2VzLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [ariadne/enums.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS9lbnVtcy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| [ariadne/types.py](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree#diff-YXJpYWRuZS90eXBlcy5weQ==) | `100% <0%> (ø)` | :arrow_up: |
| ... and [3 more](https://codecov.io/gh/mirumee/ariadne/pull/153/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=footer). Last update [aa3d994...bc9fbb3](https://codecov.io/gh/mirumee/ariadne/pull/153?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 140a270..befe10e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
 
 - Updated `graphql-core-next` to 1.0.3 which has feature parity with GraphQL.js 14.2.1 and better type annotations.
 - `ariadne.asgi.GraphQL` is now an ASGI3 application. ASGI3 is now handled by all ASGI servers.
+- `ObjectType.field` and `SubscriptionType.source` decorators now raise ValueError when used without name argument (eg. `@foo.field`).
 - Removed explicit `typing` dependency.
 - Added Flask integration example.
 
diff --git a/ariadne/objects.py b/ariadne/objects.py
index 80e1829..12c869b 100644
--- a/ariadne/objects.py
+++ b/ariadne/objects.py
@@ -14,6 +14,10 @@ class ObjectType(SchemaBindable):
         self._resolvers = {}
 
     def field(self, name: str) -> Callable[[Resolver], Resolver]:
+        if not isinstance(name, str):
+            raise ValueError(
+                'field decorator should be passed a field name: @foo.field("name")'
+            )
         return self.create_register_resolver(name)
 
     def create_register_resolver(self, name: str) -> Callable[[Resolver], Resolver]:
diff --git a/ariadne/subscriptions.py b/ariadne/subscriptions.py
index 8c371ff..8a180e3 100644
--- a/ariadne/subscriptions.py
+++ b/ariadne/subscriptions.py
@@ -14,6 +14,10 @@ class SubscriptionType(ObjectType):
         self._subscribers = {}
 
     def source(self, name: str) -> Callable[[Subscriber], Subscriber]:
+        if not isinstance(name, str):
+            raise ValueError(
+                'source decorator should be passed a field name: @foo.source("name")'
+            )
         return self.create_register_subscriber(name)
 
     def create_register_subscriber(

Raise ValueError when `field` or `source` decorator was called incorrectly
Currently there's no error when the developer forgets to follow the `field` or `source` decorator with `("name")`, tricking them into thinking that decorated function has been registered while in fact it wasn't.

We could update implementation for those functions to raise ValueError when `name` attr is not `str`.
diff --git a/tests/test_objects.py b/tests/test_objects.py
index 231c5cc..eaf5b3e 100644
--- a/tests/test_objects.py
+++ b/tests/test_objects.py
@@ -46,6 +46,12 @@ def test_field_resolver_can_be_set_using_decorator(schema):
     assert result.data == {"hello": "World"}
 
 
+def test_value_error_is_raised_if_field_decorator_was_used_without_argument():
+    query = ObjectType("Query")
+    with pytest.raises(ValueError):
+        query.field(lambda *_: "World")
+
+
 def test_field_resolver_can_be_set_using_setter(schema):
     query = ObjectType("Query")
     query.set_field("hello", lambda *_: "World")
diff --git a/tests/test_subscriptions.py b/tests/test_subscriptions.py
index aede02b..cec70c7 100644
--- a/tests/test_subscriptions.py
+++ b/tests/test_subscriptions.py
@@ -23,9 +23,9 @@ def test_field_source_can_be_set_using_setter(schema):
     async def source(*_):
         yield "test"  # pragma: no cover
 
-    sub = SubscriptionType()
-    sub.set_source("message", source)
-    sub.bind_to_schema(schema)
+    subscription = SubscriptionType()
+    subscription.set_source("message", source)
+    subscription.bind_to_schema(schema)
     field = schema.type_map.get("Subscription").fields["message"]
     assert field.subscribe is source
 
@@ -34,18 +34,27 @@ def test_field_source_can_be_set_using_decorator(schema):
     async def source(*_):
         yield "test"  # pragma: no cover
 
-    sub = SubscriptionType()
-    sub.source("message")(source)
-    sub.bind_to_schema(schema)
+    subscription = SubscriptionType()
+    subscription.source("message")(source)
+    subscription.bind_to_schema(schema)
     field = schema.type_map.get("Subscription").fields["message"]
     assert field.subscribe is source
 
 
+def test_value_error_is_raised_if_source_decorator_was_used_without_argument():
+    async def source(*_):
+        yield "test"  # pragma: no cover
+
+    subscription = SubscriptionType()
+    with pytest.raises(ValueError):
+        subscription.source(source)
+
+
 def test_attempt_bind_subscription_to_undefined_field_raises_error(schema):
     async def source(*_):
         yield "test"  # pragma: no cover
 
-    sub_map = SubscriptionType()
-    sub_map.set_source("fake", source)
+    subscription = SubscriptionType()
+    subscription.set_source("fake", source)
     with pytest.raises(ValueError):
-        sub_map.bind_to_schema(schema)
+        subscription.bind_to_schema(schema)

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-mock snapshottest
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
-e git+https://github.com/mirumee/ariadne.git@aa3d994c27a740306edace41ce66842e6a8a02a3#egg=ariadne
certifi @ file:///croot/certifi_1671487769961/work/certifi
coverage==7.2.7
exceptiongroup==1.2.2
fastdiff==0.3.0
GraphQL-core-next==1.0.3
importlib-metadata==6.7.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.2.0
pytest==7.4.4
pytest-cov==4.1.0
pytest-mock==3.11.1
six==1.17.0
snapshottest==0.6.0
starlette==0.12.0b3
termcolor==2.3.0
tomli==2.0.1
typing-extensions==3.6.6
wasmer==1.1.0
wasmer_compiler_cranelift==1.1.0
zipp==3.15.0

name: ariadne
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - ariadne==0.4.0
      - coverage==7.2.7
      - exceptiongroup==1.2.2
      - fastdiff==0.3.0
      - graphql-core-next==1.0.3
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - packaging==24.0
      - pluggy==1.2.0
      - pytest==7.4.4
      - pytest-cov==4.1.0
      - pytest-mock==3.11.1
      - six==1.17.0
      - snapshottest==0.6.0
      - starlette==0.12.0b3
      - termcolor==2.3.0
      - tomli==2.0.1
      - typing-extensions==3.6.6
      - wasmer==1.1.0
      - wasmer-compiler-cranelift==1.1.0
      - zipp==3.15.0
prefix: /opt/conda/envs/ariadne

tests/test_objects.py::test_value_error_is_raised_if_field_decorator_was_used_without_argument tests/test_subscriptions.py::test_value_error_is_raised_if_source_decorator_was_used_without_argument
tests/test_objects.py::test_attempt_bind_object_type_to_undefined_type_raises_error tests/test_objects.py::test_attempt_bind_object_type_to_invalid_type_raises_error tests/test_objects.py::test_attempt_bind_object_type_field_to_undefined_field_raises_error tests/test_objects.py::test_field_resolver_can_be_set_using_decorator tests/test_objects.py::test_field_resolver_can_be_set_using_setter tests/test_objects.py::test_set_alias_method_creates_resolver_for_specified_attribute tests/test_subscriptions.py::test_field_source_can_be_set_using_setter tests/test_subscriptions.py::test_field_source_can_be_set_using_decorator tests/test_subscriptions.py::test_attempt_bind_subscription_to_undefined_field_raises_error
ariadne/objects.py ariadne/subscriptions.py CHANGELOG.md
ariadne/objects.py ariadne/subscriptions.py CHANGELOG.md