Graphql-engine: Support for Composite types

Created on 15 Nov 2018  路  3Comments  路  Source: hasura/graphql-engine

Hi guys, I created a table with the Hasura sql console with a composite type like in the Postgres docs. I can do queries like this

query{on_hand{count item}}

And I get the response as expected:

{
  "data": {
    "on_hand": [
      {
        "count": 1000,
        "item": {
          "name": "fuzzy dice",
          "supplier_id": 42,
          "price": 1.99
        }
      },
      {
        "count": 500,
        "item": {
          "name": "fuzzy dice",
          "supplier_id": 41,
          "price": 9.99
        }
      }
    ]
  }
}

But when I try to do a mutation like this it doesn't work

mutation {
  insert_on_hand(objects: [{count: 10, item: {name: "fuzzy dice", supplier_id: 42, price: 1.99}}]) {
    returning {
      count
      item
    }
  }
}

I get this error:

{
  "errors": [
    {
      "path": "$.selectionSet.insert_on_hand.args.objects[0].item",
      "error": "unexpected object for a scalar",
      "code": "validation-failed"
    }
  ]
}

Subscriptions work by making the insert in the hasura sql console. So composite types or "user defined" types work out of the box but is it possible to add official support for it ? Thank's for the great work on the engine guys :+1:

EDIT: I tried that way too

mutation {
  insert_on_hand(objects: [{count: 10, item: {data: {name: "fuzzy dice", supplier_id: 42, price: 1.99}}}]) {
    returning {
      count
      item
    }
  }
}
server enhancement longterm

Most helpful comment

@Sach97 While we don't explicitly support row types, there is an escape hatch (for all types that are not known to graphql-engine) using Postgres literals. In your case, you can do this:

mutation {
  insert_on_hand(objects: [{count: 10, item: "('fuzzy dice',42,1.99)"}]) {
    returning {
      count
      item
    }
  }
}

All 3 comments

@Sach97 While we don't explicitly support row types, there is an escape hatch (for all types that are not known to graphql-engine) using Postgres literals. In your case, you can do this:

mutation {
  insert_on_hand(objects: [{count: 10, item: "('fuzzy dice',42,1.99)"}]) {
    returning {
      count
      item
    }
  }
}

Thank's a lot for your response ! It will do the job

@0x777 , couldnt you hypothetically scrape custom postgres types, and support them?

this would be a big boost in performance, as my schema is littered with one-to-one relationships and id love to consolidate them into row types to bring my tracked tables/relationships down

Was this page helpful?
0 / 5 - 0 ratings