prisma-tools icon indicating copy to clipboard operation
prisma-tools copied to clipboard

Union types in Prisma Select support

Open terion-name opened this issue 3 years ago • 2 comments

Union types are not supported at all :(

{
_entities(representations: [{__typename: General, id: "cjnvxsos80fwh0918ffd7ie52"}]) {
    ...on General {
      id
    	foundationYear
      agriculturalSquare
    },
    ...on AgeStat {
      population {
        ages {
          malesPercent
        }
      }
    }
  }
}

Gives:

  representations: [
    [Object: null prototype] {
      __typename: 'General',
      id: 'cjnvxsos80fwh0918ffd7ie52'
    }
  ],
  select: {
    id: true,
    foundationYear: true,
    agriculturalSquare: true,
    population: { select: [Object] }
  }

I understand that unions are not part of prisma, but it would be great to have this for custom queries.

Format TBD, but as a variant something like this:

{
  select: { __on: { General: { id: true } } }
}

terion-name avatar Jan 13 '22 14:01 terion-name

Yeah, this would be pretty good.

In a simple approach, just returning two major objects with their selections would also be sufficient, like:

{
  General: { select: { id: true } },
  AgeStat: { select: { id: true } }
}

Of course, the above just an example to clarify this idea.

arthurfiorette avatar Apr 24 '22 17:04 arthurfiorette

Guys, is there any chance to add this functionality?

mniemiec92 avatar Jul 29 '22 08:07 mniemiec92