Skip to content

Commit

Permalink
Feature/remove validation (#17)
Browse files Browse the repository at this point in the history
* release: Removed duplicate security file

* release: Removed GraphQL validation
  • Loading branch information
denisart authored May 31, 2023
1 parent d558f6e commit f8b0171
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 76 deletions.
7 changes: 0 additions & 7 deletions SECUTIRY.md

This file was deleted.

58 changes: 0 additions & 58 deletions graphql_query/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from pathlib import Path
from typing import Any, List, Optional, Union

from graphql import assert_name
from jinja2 import Environment, FileSystemLoader, Template
from pydantic import BaseModel
from pydantic import Field as PydanticField
from pydantic import validator

if sys.version_info >= (3, 10):
from typing import TypeGuard
Expand Down Expand Up @@ -97,10 +95,6 @@ class Variable(_GraphQL2PythonQuery):

_template: Template = template_env.get_template("variable.jinja2")

@validator("name")
def graphql_variable_name(cls, name: str) -> str:
return assert_name(name)

def render(self) -> str:
return self._template.render(name=self.name, type=self.type, default=self.default)

Expand Down Expand Up @@ -185,10 +179,6 @@ class Argument(_GraphQL2PythonQuery):
_template_key_arguments: Template = template_env.get_template("argument_key_arguments.jinja2")
_template_key_objects: Template = template_env.get_template("argument_key_objects.jinja2")

@validator("name")
def graphql_argument_name(cls, name: str) -> str:
return assert_name(name)

@staticmethod
def _check_is_list_of_str(values: List[Any]) -> TypeGuard[List[str]]:
return all(isinstance(value, str) for value in values)
Expand Down Expand Up @@ -297,10 +287,6 @@ class Directive(_GraphQL2PythonQuery):

_template_directive: Template = template_env.get_template("directive.jinja2")

@validator("name")
def graphql_directive_name(cls, name: str) -> str:
return assert_name(name)

def render(self) -> str:
return self._template_directive.render(
name=self.name, arguments=[self._line_shift(argument.render()) for argument in self.arguments]
Expand Down Expand Up @@ -367,16 +353,6 @@ class Field(_GraphQL2PythonQuery):

_template: Template = template_env.get_template("field.jinja2")

@validator("name")
def graphql_field_name(cls, name: str) -> str:
return assert_name(name)

@validator("alias")
def graphql_field_alias(cls, alias: Optional[str]) -> Optional[str]:
if alias is not None:
return assert_name(alias)
return alias

def render(self) -> str:
return self._template.render(
name=self.name,
Expand Down Expand Up @@ -431,14 +407,6 @@ class InlineFragment(_GraphQL2PythonQuery):

_template: Template = template_env.get_template("inline_fragment.jinja2")

@validator("fields")
def graphql_inline_fragment_fields(
cls, fields: List[Union[str, 'Field', 'InlineFragment', 'Fragment']]
) -> List[Union[str, 'Field', 'InlineFragment', 'Fragment']]:
if len(fields) == 0:
raise ValueError("empty fields for this inline fragment")
return fields

def render(self) -> str:
return self._template.render(
type=self.type,
Expand Down Expand Up @@ -499,10 +467,6 @@ class Fragment(_GraphQL2PythonQuery):

_template: Template = template_env.get_template("fragment.jinja2")

@validator("name")
def graphql_fragment_name(cls, name: str) -> str:
return assert_name(name)

def render(self) -> str:
return self._template.render(
name=self.name,
Expand Down Expand Up @@ -558,16 +522,6 @@ class Query(_GraphQL2PythonQuery):

_template: Template = template_env.get_template("query.jinja2")

@validator("name")
def graphql_query_name(cls, name: str) -> str:
return assert_name(name)

@validator("alias")
def graphql_alias_alias(cls, alias: Optional[str]) -> Optional[str]:
if alias is not None:
return assert_name(alias)
return alias

def render(self) -> str:
return self._template.render(
name=self.name,
Expand Down Expand Up @@ -639,18 +593,6 @@ class Operation(_GraphQL2PythonQuery):
_template: Template = template_env.get_template("operation.jinja2")
_supported_types = ["query", "mutation", "subscription"]

@validator("name")
def graphql_operation_name(cls, name: Optional[str]) -> Optional[str]:
if name is not None:
return assert_name(name)
return name

@validator("queries")
def graphql_queries(cls, queries: List[Query]) -> List[Query]:
if len(queries) == 0:
raise ValueError("empty queries list for this operation")
return queries

def render(self) -> str:
return self._template.render(
type=self.type,
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ requires-python = ">=3.7"
dependencies = [
"pydantic>=1.10, <1.11",
"jinja2>=3.1, <3.2",
"graphql-core>=3.2, <3.3",
]
dynamic = ["version"]

Expand Down
5 changes: 0 additions & 5 deletions tests/test_inline_fragment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,3 @@ def test_inline_fragment(
):
fragment = InlineFragment(type=type, arguments=arguments, fields=fields, typename=typename)
assert fragment.render() == result


def test_empty_fields():
with pytest.raises(ValueError):
_ = InlineFragment(type="Type", fields=[])
5 changes: 0 additions & 5 deletions tests/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,3 @@ def test_operation(
operation = Operation(type=type, name=name, variables=variables, queries=queries, fragments=fragments)

assert operation.render() == result


def test_empty_queries_list():
with pytest.raises(ValueError):
_ = Operation(type="query", queries=[])

0 comments on commit f8b0171

Please sign in to comment.