hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.08k stars 2.77k forks source link

[Error] Unknown operator in console browse rows #3001

Open bynov opened 4 years ago

bynov commented 4 years ago

Hi! I'm using Browse Rows in Hasura console. When I open my table "orders" and try to open row data from table "offers" by foreign key "fk_orders_offer_id", I've got an error "Unknown operator : participant_method". My table scheme:

Orders:

                               Table "public.orders"
         Column         |           Type           | Collation | Nullable | Default
------------------------+--------------------------+-----------+----------+---------
 id                     | character(36)            |           | not null |
 offer_id               | character(36)            |           | not null |
 tracking_id            | character varying(50)    |           |          |
 buyer_delivery_info_id | character(36)            |           | not null |
 created_at             | timestamp with time zone |           | not null | now()
 fee_amount             | integer                  |           |          |
 fee_currency           | character varying(3)     |           |          |
 fee_details            | json                     |           |          |
 seller_fee_details     | jsonb                    |           |          |
 buyer_fee_details      | jsonb                    |           |          |
Indexes:
    "orders_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "fk_orders_offer_id" FOREIGN KEY (offer_id) REFERENCES offers(id)
    "orders_buyer_delivery_info_id_fkey" FOREIGN KEY (buyer_delivery_info_id) REFERENCES info(id)
Referenced by:
    TABLE "cancel_details" CONSTRAINT "cancel_details_order_id_fkey" FOREIGN KEY (order_id) REFERENCES orders(id)
    TABLE "request_queue" CONSTRAINT "request_queue_order_id_fkey" FOREIGN KEY (order_id) REFERENCES orders(id)
    TABLE "statuses" CONSTRAINT "statuses_order_id_fkey" FOREIGN KEY (order_id) REFERENCES orders(id)

Offers:

                                                Table "public.offers"
         Column          |         Type          | Collation | Nullable |                  Default
-------------------------+-----------------------+-----------+----------+--------------------------------------------
 id                      | character(36)         |           | not null |
 state                   | character varying(30) |           | not null | 'deactivated_by_seller'::character varying
 ad_id                   | character varying(30) |           |          |
 ad_subject              | character varying(50) |           | not null |
 ad_image_id             | character varying(50) |           |          |
 ad_price                | integer               |           | not null |
 seller_delivery_info_id | character(36)         |           | not null |
 ad_currency             | character(3)          |           |          |
 ad_region               | character varying(36) |           |          |
 ad_area                 | character varying(36) |           |          |
 ad_category             | character varying(36) |           |          |
 ad_body                 | text                  |           |          |
 ad_event                | text                  |           |          |
Indexes:
    "offers_pkey" PRIMARY KEY, btree (id)
    "idx_offers_ad_id" UNIQUE, btree (ad_id)
Foreign-key constraints:
    "offers_seller_delivery_info_id_fkey" FOREIGN KEY (seller_delivery_info_id) REFERENCES info(id)
Referenced by:
    TABLE "orders" CONSTRAINT "fk_orders_offer_id" FOREIGN KEY (offer_id) REFERENCES offers(id)

Column seller_fee_details contains data like this:

{
    "fee": {
        "amount": 1,
        "currency": "USD"
    },
    "total": {
        "amount": 10,
        "currency": "USD"
    },
    "ad_price": {
        "amount": 5,
        "currency": "USD"
    },
    "fixed_fee": {
        "amount": 1,
        "currency": "USD"
    },
    "provider_code": "Provider1",
    "participant_type": "seller",
    "participant_method": "O"
}

Hasura Engine error log:

{
    "timestamp": "2019-10-03T12:48:57.743+0000",
    "level": "error",
    "type": "http-log",
    "detail": {
        "operation": {
            "query_execution_time": null,
            "user_vars": {
                "x-hasura-role": "admin"
            },
            "error": {
                "path": "$.args[0].args.where.seller_fee_details.participant_method",
                "error": "Unknown operator : participant_method",
                "code": "unexpected-payload"
            },
            "request_id": "c49bf5a648d0b22965196d85957063d6",
            "response_size": 145,
            "query": {
                "args": [{
                    "args": {
                        "where": {
                            "offer_id": "id",
                            "tracking_id": "",
                            "fee_amount": null,
                            "seller_fee_details": {
                                "participant_method": "O",
                                "participant_type": "seller",
                                "provider_code": "Provider1",
                                "fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "ad_price": {
                                    "amount": 10,
                                    "currency": "USD"
                                },
                                "fixed_fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "total": {
                                    "amount": 10,
                                    "currency": "USD"
                                }
                            },
                            "fee_details": null,
                            "fee_currency": null,
                            "created_at": "2019-05-17T10:59:10.033801+00:00",
                            "buyer_fee_details": {
                                "participant_method": "O",
                                "participant_type": "buyer",
                                "provider_code": "Provider1",
                                "fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "ad_price": {
                                    "amount": 10,
                                    "currency": "USD"
                                },
                                "percent_of_price": 2,
                                "fixed_fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "total": {
                                    "amount": 20,
                                    "currency": "USD"
                                }
                            },
                            "id": "1b45d4cc-822c",
                            "buyer_delivery_info_id": "d092fd3b-6a9c"
                        },
                        "offset": null,
                        "order_by": null,
                        "columns": ["id", "offer_id", "tracking_id", "buyer_delivery_info_id", "created_at", "fee_amount", "fee_currency", "fee_details", "seller_fee_details", "buyer_fee_details", {
                            "where": null,
                            "offset": null,
                            "alias": null,
                            "name": "offer",
                            "order_by": null,
                            "columns": ["id", "state", "ad_id", "ad_subject", "ad_image_id", "ad_price", "seller_delivery_info_id", "ad_currency", "ad_region", "ad_area", "ad_category", "ad_body", "ad_event"],
                            "limit": null
                        }],
                        "limit": null,
                        "table": "orders"
                    },
                    "type": "select"
                }, {
                    "args": {
                        "where": {
                            "offer_id": "id",
                            "tracking_id": "",
                            "fee_amount": null,
                            "seller_fee_details": {
                                "participant_method": "O",
                                "participant_type": "seller",
                                "provider_code": "Provider1",
                                "fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "ad_price": {
                                    "amount": 10,
                                    "currency": "USD"
                                },
                                "fixed_fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "total": {
                                    "amount": 10,
                                    "currency": "USD"
                                }
                            },
                            "fee_details": null,
                            "fee_currency": null,
                            "created_at": "2019-05-17T10:59:10.033801+00:00",
                            "buyer_fee_details": {
                                "participant_method": "O",
                                "participant_type": "buyer",
                                "provider_code": "Provider1",
                                "fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "ad_price": {
                                    "amount": 10,
                                    "currency": "USD"
                                },
                                "percent_of_price": 2,
                                "fixed_fee": {
                                    "amount": 1,
                                    "currency": "USD"
                                },
                                "total": {
                                    "amount": 20,
                                    "currency": "USD"
                                }
                            },
                            "id": "1b45d4cc-822c",
                            "buyer_delivery_info_id": "d092fd3b-6a9c"
                        },
                        "table": "orders"
                    },
                    "type": "count"
                }],
                "type": "bulk"
            }
        },
        "http_info": {
            "status": 400,
            "http_version": "HTTP/1.1",
            "url": "/v1/query",
            "ip": "xxx,xxx:60194",
            "method": "POST"
        }
    }
}

I think it something related to jsonb but I can't figure it out. Maybe somebody has similar error? Thanks.

0x777 commented 4 years ago

@rikinsk Looks like the console is using all the columns to generate the where condition to get the relationship information of the selected row. The console should use "column": {"_eq": value} instead of "column": value. The second form is a syntactic convenience which only works for non-json(b) columns. Since in the above case, seller_fee_details and buyer_fee_details are columns of type jsonb, the query that the console generates is rejected by the server.