Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to orderBy nullable field with clientDialect typegraphql #143

Open
Mweydert opened this issue May 14, 2024 · 0 comments
Open

Comments

@Mweydert
Copy link

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

  • API is an apollo server using typegraphql with Prisma as the ORM (thus typegraphql-prisma package).
  • Front is react-admin with this package as the data provider. I'm using an apollo client and 'typegraphqlas thequeryDialect`.

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:

  • For nullable fields, typegraphql expect the sort params to be an object
  • We always send 'asc' or 'desc' as sort params

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant