Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fragments Updates #79

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/docker-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
branches: [master]
pull_request:
branches: [master]

jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
python-version: [3.9, "3.10", "3.11", "3.12"]
poetry-version: [1.4.2]
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "turms"
version = "0.5.0"
version = "0.7.0"
description = "graphql-codegen powered by pydantic"
authors = ["jhnnsrs <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_multi_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ def test_fragment_generation(multi_interface_schema):

unit_test_with(
generated_ast,
"assert FlowNodeBaseReactiveNode(id='soinosins', position={'x': 3, 'y': 3}).id, 'Needs to be not nown'",
"assert FlowNodesBaseReactiveNode(id='soinosins', position={'x': 3, 'y': 3}).id, 'Needs to be not nown'",
)
24 changes: 15 additions & 9 deletions turms/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import builtins
from pydantic import AnyHttpUrl, BaseModel, Field, GetCoreSchemaHandler, field_validator, validator, ConfigDict
from pydantic import (
AnyHttpUrl,
BaseModel,
Field,
GetCoreSchemaHandler,
field_validator,
validator,
ConfigDict,
)
from pydantic_core import core_schema
from pydantic_settings import BaseSettings, SettingsConfigDict
from typing import (
Expand All @@ -22,7 +30,6 @@ class ConfigProxy(BaseModel):
type: str



class ImportableFunctionMixin(Protocol):

@classmethod
Expand All @@ -33,7 +40,6 @@ def __get_pydantic_core_schema__(
cls.validate, handler(callable), field_name=handler.field_name
)


@classmethod
def validate(cls, v, *info):
if not callable(v):
Expand All @@ -57,7 +63,6 @@ def __get_pydantic_core_schema__(
cls.validate, handler(str), field_name=handler.field_name
)


@classmethod
def validate(cls, v, *info):
if not isinstance(v, str):
Expand Down Expand Up @@ -147,7 +152,7 @@ class OptionsConfig(BaseSettings):

enabled: bool = Field(False, description="Enabling this, will freeze the schema")
"""Enabling this, will freeze the schema"""
extra: ExtraOptions = None
extra: ExtraOptions = None
"""Extra options for pydantic"""
allow_mutation: Optional[bool] = None
"""Allow mutation"""
Expand Down Expand Up @@ -179,6 +184,7 @@ class OptionsConfig(BaseSettings):

PydanticVersion = Literal["v1", "v2"]


class GeneratorConfig(BaseSettings):
"""Configuration for the generator

Expand All @@ -189,11 +195,10 @@ class GeneratorConfig(BaseSettings):
and the scalars that should be used.

"""

model_config: SettingsConfigDict = SettingsConfigDict(
env_prefix="TURMS_",
extra="forbid",


)
pydantic_version: PydanticVersion = "v2"

Expand Down Expand Up @@ -291,7 +296,6 @@ def validate_importable(cls, v):
return v



class Extensions(BaseModel):
"""Wrapping class to be able to extract the tums configuraiton"""

Expand All @@ -317,6 +321,7 @@ class GraphQLProject(BaseSettings):
Turm will use the schema and documents to generate the python models, according
to the generator configuration under extensions.turms
"""

model_config: SettingsConfigDict = SettingsConfigDict(
env_prefix="TURMS_GRAPHQL_",
extra="allow",
Expand All @@ -335,6 +340,7 @@ class GraphQLConfigMultiple(BaseSettings):

This is the main configuration for multiple GraphQL projects. It is compliant with
the graphql-config specification for multiple projec."""

model_config: SettingsConfigDict = SettingsConfigDict(
extra="allow",
)
Expand All @@ -343,13 +349,13 @@ class GraphQLConfigMultiple(BaseSettings):
""" The projects that should be parsed. The key is the name of the project and the value is the graphql project"""



class GraphQLConfigSingle(GraphQLProject):
"""Configuration for a single GraphQL project

This is the main configuration for a single GraphQL project. It is compliant with
the graphql-config specification for a single project.
"""

model_config: SettingsConfigDict = SettingsConfigDict(
extra="allow",
)
8 changes: 5 additions & 3 deletions turms/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ def load_dsl_from_url(url: AnyHttpUrl, headers: Dict[str, str] = None) -> DSLStr
default_headers.update(headers)
try:
req = requests.get(url, headers=default_headers)
x = req.text()
except Exception:
raise GenerationError(f"Failed to fetch schema from {url}")
assert req.status_code == 200, "Incorrect status code"
assert req.content, "No content"
x = req.content.decode()
except Exception as e:
raise GenerationError(f"Failed to fetch schema from {url}") from e
return x


Expand Down
1 change: 0 additions & 1 deletion turms/parsers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ParserConfig(BaseSettings):
type: str



class Parser(BaseModel):
"""Base class for all parsers

Expand Down
1 change: 0 additions & 1 deletion turms/parsers/polyfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def validate_python_version(cls, value):
return value



def polyfill_python_seven(
asts: List[ast.AST], config: PolyfillPluginConfig
) -> List[ast.AST]:
Expand Down
2 changes: 1 addition & 1 deletion turms/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class PluginConfig(BaseSettings):
type: str



class Plugin(BaseModel):
"""
Base class for all plugins

Plugins are the workhorse of turms. They are used to generate python code, according
to the GraphQL schema. You can use plugins to generate python code for your GraphQL
schema. THe all received the graphql schema and the config of the plugin."""

model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
config: PluginConfig
log: LogFunction = Field(default=lambda *args, **kwargs: print(*args))
Expand Down
Loading
Loading