Skip to content

[REFACTOR] Rewrite QueryBuilder to use gqlrequests #12

@ericbstie

Description

@ericbstie

Refactor description

I suggest refactoring QueryBuilder to use gqlrequests instead.

So instead of many of these types of dicts:

    @classmethod
    @property
    def price_rating_entry(cls) -> dict:
        """Return a dict with query values as keys for all information on the `PriceRatingEntry` type."""
        return {
            "time": "",
            "energy": 0.0,
            "total": 0.0,
            "tax": 0.0,
            "difference": 0.0,
            "level": ""
        }

all types would be defined like this:

from gqlrequests import QueryBuilder

class PriceRatingEntry(QueryBuilder):
    """Return a dict with query values as keys for all information on the `PriceRatingEntry` type."""
    time: str
    energy: float
    total: float
    tax: float
    difference: float
    level: str

gql_client.query(PriceRatingEntry().build())

Why this should be refactored

The way QueryBuilder works now, it's hard to expand on and is very cluttered. The logic of how a query is created
from a dict is not so intuitive or easy to grasp. Also, everything is in a single file and would get even longer and
harder to read if more types were to be added to the API.

Using gqlrequests, you could refactor QueryBuilder into multiple files and have a much more similar representation of the
Tibber API GraphQL types than you can with the way QueryBuilder is created now.

What breaking changes does this have for the end-user

Refactoring the QueryBuilder will not change anything for the end-user. This could result in the library being
compatible with python version 3.8 as well (since it gets rid of the @classmethod and @property
decorator combination, which results in errors in python versions prior to 3.9).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthigh priorityThis issue should be looked into in the near future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions