Has anyone worked with apollo graphql studio, in r...
# orm-help
n
Has anyone worked with apollo graphql studio, in regards to DateTime and Date? I can't pass it as a string, guess this is a missing feature not 100% any ideas?
r
Are you passing an ISO string?
n
Nothing atm @Ryan
dateOfBirth: "2021-11-03"
r
Passing this should work:
2021-11-03T00:00:00.000Z
.
n
@Ryan that doesn't work either, i've tried it 😞
dateOfBirth: Date
in typescript then it's throwing:
Copy code
Argument dateOfBirth: Got invalid value null on prisma.createOneBeneficialOwner. Provided null, expected DateTime.
r
You’re passing the correct argument here? Prisma is saying that you have provided
null
.
n
correct, however my graphql dto on the resolver has a type of
Date
which if it's not
Date
it will return null
which if i pass the
Date
it will resolve as
yyyy-mm-dd
etc vs the timestamp will break the strict type of
Date
as it's expecting
DateTime
on the prisma side
in my schema i set dateOfBirth to
DateTime
with
@db.date
r
Yes but in Prisma, you still need to pass an entire date, either the
Date
object or the ISO string. So you would need to have the
DateTime
scalar setup in GraphQL
n
found the issue ryan, it was my scalar was returning null but changed to:
Copy code
import {
  CustomScalar,
  Scalar,
} from '@nestjs/graphql';
import { Kind } from 'graphql';

@Scalar('Date', () => Date)
export class DateScalar implements CustomScalar<string, Date> {
  public description = 'Date custom scalar type';

  public parseValue(value: string): Date {
    return new Date(value); // value from the client
  }

  public serialize(value: Date): string {
    return new Date(value).toISOString(); // value sent to the client
  }

  // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
  public parseLiteral(ast: any): any {
    if (ast.kind === <http://Kind.INT|Kind.INT>) {
      return new Date(ast.value);
    }

    return new Date(ast.value).toISOString();
  }
}
👍 1