panter / ra-data-prisma

Packages to connect react-admin with prisma version 2
MIT License
85 stars 28 forks source link

Impossible to orderBy nullable field with clientDialect `typegraphql` #143

Open Mweydert opened 6 months ago

Mweydert commented 6 months ago

Hello and first of all thanks for your work on this library :-)

I came accross what seems to be a bug in the sorting of nullable fields with typegraphql query dialect.

My stack

Error

Wen I want to sort a column by a nullable field (e.g. firstName), the ApolloProvider yells this error: ApolloError: Variable "$orderBy" got invalid value "desc" at "orderBy[0].firstName"; Expected type "SortOrderInput" to be an object..

The GraphQL types, generated by typegraphql-prisma are the following :

export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;

export enum SortOrder {
  asc = 'asc',
  desc = 'desc',
}

export type SortOrderInput = {
  nulls?: InputMaybe<NullsOrder>;
  sort: SortOrder;
};

export type MyResourceOrderByWithRelationInput = {
  exampleOfWorkingField?: InputMaybe<SortOrder>;
  firstName?: InputMaybe<SortOrderInput>;
};

The error thrown seems legit to me:

I digged a bit into the source code where the orderBy params are built but I don't figured out any way to workaround this issue.

Do you have a suggestion ?

Thanks for your help !