Skip to content

Configurations#

QtGqlConfig #

Encapsulates configurations for a qtgql-codegen application per GraphQL schema.

Source code in qtgqlcodegen/config.py
@define(slots=False)
class QtGqlConfig:
    """Encapsulates configurations for a qtgql-codegen application per GraphQL
    schema."""

    graphql_dir: Path
    """A directory contains.

    - schema.graphql, represents the current schema definition at the server.
    - operations.graphql, queries, mutations and subscription handlers would be generated based on the operations defined there.
    """
    env_name: str = "QGqlEnv"
    """The generated types would find the environment by this name.

    Also the generated QML imports would fall under this namespace.
    """
    custom_scalars: CustomScalarMap = Factory(dict)
    """Mapping of custom scalars, respected by the schema evaluator."""
    qml_plugins_path: str = "${CMAKE_BINARY_DIR}/qml"
    """Qml plugins would be installed under this directory.

    This should suffice for most basic setups.
    """

    generated_dir_name: str = "__generated__"
    """The name of the directory that qtgql will create and dump the generated
    sources."""

    @cached_property
    def schema_path(self) -> Path:
        return self.graphql_dir / "schema.graphql"

    @cached_property
    def operations_dir(self) -> Path:
        return self.graphql_dir / "operations.graphql"

    @cached_property
    def generated_dir(self) -> Path:
        ret = self.graphql_dir / self.generated_dir_name
        if not ret.exists():
            ret.mkdir()
        return ret

    @cached_property
    def _evaluator(self) -> SchemaGenerator:
        return SchemaGenerator(
            config=self,
            schema=graphql.build_schema(
                (self.graphql_dir / "schema.graphql").resolve(True).read_text("utf-8"),
            ),
        )

    @property
    def shared_lib_export_definition(self) -> str:
        return f"QTGQL_{self.env_name}_EXPORT" f""

    def generate(self) -> None:
        self._evaluator.dump()

    def __attrs_post_init__(self):
        if self.custom_scalars != CUSTOM_SCALARS:
            self.custom_scalars.update(CUSTOM_SCALARS)

custom_scalars: CustomScalarMap = Factory(dict) class-attribute instance-attribute #

Mapping of custom scalars, respected by the schema evaluator.

env_name: str = 'QGqlEnv' class-attribute instance-attribute #

The generated types would find the environment by this name.

Also the generated QML imports would fall under this namespace.

generated_dir_name: str = '__generated__' class-attribute instance-attribute #

The name of the directory that qtgql will create and dump the generated sources.

graphql_dir: Path instance-attribute #

A directory contains.

  • schema.graphql, represents the current schema definition at the server.
  • operations.graphql, queries, mutations and subscription handlers would be generated based on the operations defined there.

qml_plugins_path: str = '${CMAKE_BINARY_DIR}/qml' class-attribute instance-attribute #

Qml plugins would be installed under this directory.

This should suffice for most basic setups.