Skip to content

Commit e534c5a

Browse files
author
nambrosini
committed
🔧 Avoid shipping it as new rule, as mutations have a nested input best practice
1 parent 6d1e48b commit e534c5a

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

‎schemadiff/validation_rules/__init__.py‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def is_valid(self) -> bool:
6262
else:
6363
return type_has_description
6464

65-
return True
66-
6765
@property
6866
def message(self):
6967
return f"{self.change.message} without a description for {self.change.path} (rule: `{self.name}`)."
@@ -146,26 +144,3 @@ def message(self):
146144
return f"Description for enum value `{self.change.name}` was removed (rule: `{self.name}`)"
147145

148146

149-
class MutationWithTooManyArguments(ValidationRule):
150-
"""Restrict adding fields with too many top level arguments"""
151-
152-
name = "field-has-too-many-arguments"
153-
limit = 10
154-
155-
def is_valid(self) -> bool:
156-
if not isinstance(self.change, (ObjectTypeFieldAdded, FieldArgumentAdded)):
157-
return True
158-
159-
if len(self.args) > self.limit:
160-
return False
161-
else:
162-
return True
163-
164-
@property
165-
def args(self):
166-
return self.change.field.args or {}
167-
168-
@property
169-
def message(self):
170-
return f"Field `{self.change.parent.name}.{self.change.field_name}` has too many arguments " \
171-
f"({len(self.args)}>{self.limit}). Rule: {self.name}"

‎tests/test_validation_rules.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from graphql import build_schema as schema
33

44
from schemadiff.changes import Change, Criticality
5+
from schemadiff.changes.field import FieldArgumentAdded
6+
from schemadiff.changes.object import ObjectTypeFieldAdded
57
from schemadiff.validation import evaluate_rules, ValidationResult, ValidationError
68
from schemadiff.validation_rules import (
79
ValidationRule,
@@ -234,6 +236,30 @@ def test_schema_added_field_no_desc():
234236
def test_cant_create_mutation_with_more_than_10_arguments():
235237
schema_restrictions = ['field-has-too-many-arguments']
236238

239+
class FieldHasTooManyArguments(ValidationRule):
240+
"""Restrict adding fields with too many top level arguments"""
241+
242+
name = "field-has-too-many-arguments"
243+
limit = 10
244+
245+
def is_valid(self) -> bool:
246+
if not isinstance(self.change, (ObjectTypeFieldAdded, FieldArgumentAdded)):
247+
return True
248+
249+
if len(self.args) > self.limit:
250+
return False
251+
else:
252+
return True
253+
254+
@property
255+
def args(self):
256+
return self.change.field.args or {}
257+
258+
@property
259+
def message(self):
260+
return f"Field `{self.change.parent.name}.{self.change.field_name}` has too many arguments " \
261+
f"({len(self.args)}>{self.limit}). Rule: {self.name}"
262+
237263
old_schema = schema("""
238264
schema {
239265
mutation: Mutation
@@ -274,6 +300,30 @@ def test_cant_create_mutation_with_more_than_10_arguments():
274300
def test_cant_add_arguments_to_mutation_if_exceeds_10_args():
275301
schema_restrictions = ['field-has-too-many-arguments']
276302

303+
class FieldHasTooManyArguments(ValidationRule):
304+
"""Restrict adding fields with too many top level arguments"""
305+
306+
name = "field-has-too-many-arguments"
307+
limit = 10
308+
309+
def is_valid(self) -> bool:
310+
if not isinstance(self.change, (ObjectTypeFieldAdded, FieldArgumentAdded)):
311+
return True
312+
313+
if len(self.args) > self.limit:
314+
return False
315+
else:
316+
return True
317+
318+
@property
319+
def args(self):
320+
return self.change.field.args or {}
321+
322+
@property
323+
def message(self):
324+
return f"Field `{self.change.parent.name}.{self.change.field_name}` has too many arguments " \
325+
f"({len(self.args)}>{self.limit}). Rule: {self.name}"
326+
277327
old_schema = schema("""
278328
schema {
279329
mutation: Mutation

0 commit comments

Comments
 (0)