Graphql: show Mysql DB in using graphql with python

Graphql: show Mysql DB in using graphql with python


0

I have a mysql table, which i want to represent using graphQL, I have tried something using ariandne,
and i am able to get the rows.
Now, I want to introduce functionality of where clause as well, One way could be to have a resolver for each column, but that has its limitations, and can not scale with columns increasing,
can you please suggest something.

My code:


class SSREvent(TypedDict):
    event_id: int
    start_date_time: datetime
    start_date_time_UTC: datetime
    epg_num: str
    duration: timedelta
    end_date_time: datetime
    end_date_time_UTC: datetime
    prog_name: str


def all_ssr_events() -> List[SSREvent]:
    connection = mysql.connector.connect(**DB_CONFIG)

    try:
        with connection.cursor(dictionary=True) as cursor:
            query = f"SELECT * FROM SSR_EVENTS"
            cursor.execute(query)
            data = cursor.fetchall()
            result = [SSREvent(**i) for i in data]
            return result

    except Exception as e:
        return e

    finally:
        connection.close()


EVENT_TYPEDEF = """
    scalar GraphQLDateTime
    scalar GraphQLDate
    scalar GraphQLTime


    type SSREvent {
        event_id : Int!
        start_date_time : GraphQLDateTime!
        start_date_time_UTC : GraphQLDateTime!
        epg_num : String!
        duration : String!
        end_date_time : GraphQLDateTime!
        end_date_time_UTC : GraphQLDateTime!
        prog_name : String!
    }
"""

ssr_event_query = ObjectType("SSREvent")


@query.field("ssr_events")
def resolve_ssr_events(_, info: GraphQLResolveInfo) -> list[SSREvent]:
    data: list[SSREvent] = all_ssr_events()
    return data



this is ariande library, Do I need to change it or something?
I need to filter the results based on one or more columns, a feature similar to where clause in sql

Share


Load 7 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *