paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
687 stars 55 forks source link

Union types in Prisma Select support #249

Open terion-name opened 2 years ago

terion-name commented 2 years ago

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 } } }
}
arthurfiorette commented 2 years ago

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.

mniemiec92 commented 2 years ago

Guys, is there any chance to add this functionality?