hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Array of enums not supported

Open ondratra opened this issue 2 years ago • 0 comments

There is no way how to create a list of enums.

The following input schema will generate uncompilable code:

enum ChannelActionPermission {
  UpdateChannelMetadata
  ManageNonVideoChannelAssets
  ManageChannelCollaborators
  UpdateVideoMetadata
  AddVideo
  ManageVideoAssets
  DeleteChannel
  DeleteVideo
  ManageVideoNfts
  AgentRemark
  TransferChannel
  ClaimChannelReward
  WithdrawFromChannelBalance
  IssueCreatorToken
  ClaimCreatorTokenPatronage
  InitAndManageCreatorTokenSale
  CreatorTokenIssuerTransfer
  MakeCreatorTokenPermissionless
  ReduceCreatorTokenPatronageRate
  ManageRevenueSplits
  DeissueCreatorToken
}

type ChannelAgentPermissions @entity {
  ...

  "List of member's permissions"
  permissions: [ChannelActionPermission!]!
}

The generated snippet in channel-agent-permissions.model.ts doesn't represent the schema (there is enum instead of array of enums created):

 @EnumField('ChannelActionPermission', ChannelActionPermission, {
    description: `List of member's permissions`,
  })
  permissions!: ChannelActionPermission;

After manually changing the generated code to

  @EnumField('ChannelActionPermission', ChannelActionPermission, {
    description: `List of member's permissions`,
    array: true, // none of these two works
    isArray: true, // none of these two works
  })
  permissions!: ChannelActionPermission[];

the code compiles, but an error during db setup occurs:

DataTypeNotSupportedError: Data type "Array" in "ChannelAgentPermissions.permissions" is not supported by "postgres" database

This will require a change in Warthog's EnumField decorator. I wasn't able to make it work in a couple of hours, so I'm putting it on ice for now.

ondratra avatar Aug 10 '22 20:08 ondratra