0

Here is my GQL... (note the variable $rrule)

mutation CREATE(
  $title: String!,
  $description: String!,
  $duration: interval!,
  $photo_url: String,
  $rrule: String!,
  $venue_id: Int!
) {
  result:insert_event_templates_one(
    object: {
      title: $title,
      description: $description,
      duration: $duration,
      photo_url: $photo_url,
      rrule: $rrule,
      venue_id: $venue_id
    }      
  ) {
    id
  }
}

rrule is a custom column type in another schema: _rrule It can an implicit cast defined as follows:

CREATE CAST (TEXT AS _rrule.RRULE)
  WITH FUNCTION _rrule.rrule(TEXT)
  AS IMPLICIT;

How do I define my mutation to reference that cast? Right now when I run this mutation I get the following error:

variable rrule of type String! is used in position expecting rrule

So Hasura seems to know the underlying column type, but can't use its implicit cast?

Trey Stout
  • 6,231
  • 3
  • 24
  • 27

1 Answers1

1

The error does not have anything to do with the underlying datasource. The argument where the $rrule variable is being used accepts a GraphQL type named rrule. A variable can only be passed to an argument if its type matches. So the type of $rrule must be the same as the type of the argument rrule -- that is, it's type should also be rrule.

mutation CREATE(
  $rrule: rrule!
  ...
) {
...
}
Daniel Rearden
  • 80,636
  • 11
  • 185
  • 183
  • Thanks for the answer. You are correct, this got me closer to the actual error which was my hunch that it can't use `rrule` as it's defined in another schema (`_rrule.RRule`). I ended up making a dummy column to hold text and then using an after insert/update trigger to convert the text to the proper type in another column – Trey Stout Jul 27 '20 at 19:53