Skip to content

Endpoint throws TypeError of JSON encoding, using mutation with input types. #264

@EdgarDegas

Description

@EdgarDegas

🐜 Bug Report

I'm using code generation. And I send mutations like this:

op = mutation_log_ticket_check()
endpoint(op, variables={
    "ticketId": ticket_id,
    "act": act,
    "reason": reason,
    "info": info,
})

This throws an error TypeError: Object of type TicketCheckLogInfo is not JSON serializable, where info is an instance of an input type TicketCheckLogInfo:

class TicketCheckLogInfo(sgqlc.types.Input):
    __schema__ = types
    __field_names__ = ('summary', 'confidence', 'comment', 'is_tech', 'category')
    summary = sgqlc.types.Field(String, graphql_name='summary')
    confidence = sgqlc.types.Field(Int, graphql_name='confidence')
    comment = sgqlc.types.Field(String, graphql_name='comment')
    is_tech = sgqlc.types.Field(Boolean, graphql_name='isTech')
    category = sgqlc.types.Field(String, graphql_name='category')

Expected Behavior

I'm using code generation, so I suppose instances of generated input types would fit in the variable slots of operations, which are code that's also generated.

Please tell me if I'm using this lib in a wrong way and, if so, how to integrate input types into operations correctly.

Right now I'm using this as a workaround:

"info": TicketCheckLogInfo.__to_json_value__(info),

Current Behavior

Apparently, HTTPEndpoint.__call__ just dumps the variables dict into JSON.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions