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

CustomScalar parseLiteral doesn't allow null return type #3176

Open
2 of 4 tasks
silto opened this issue Mar 5, 2024 · 2 comments
Open
2 of 4 tasks

CustomScalar parseLiteral doesn't allow null return type #3176

silto opened this issue Mar 5, 2024 · 2 comments

Comments

@silto
Copy link

silto commented Mar 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The issue is basically the same as this one: #222
That was previously fixed in this PR: #749

The sample code in the docs for the parseLiteral method of custom scalar is this:

parseLiteral(ast: ValueNode): Date {
    if (ast.kind === Kind.INT) {
      return new Date(ast.value);
    }
    return null;
  }

But with TS strictNullChecks enabled, it results in an error.

The fix in the PR was to use some graphql types that used "Maybe" synthax to allow for the null return type, but it looks like the types of the graphql module have changed since then and don't include "Maybe" in the return type anymore, resulting in the same type issue reappearing.

Minimum reproduction code

https://github.com/nestjs/nest/blob/master/sample/12-graphql-schema-first/src/common/scalars/date.scalar.ts

Steps to reproduce

No response

Expected behavior

CustomScalar should allow parseLiteral to return null or undefined as demonstrated by the samples.

Package version

12.0.4

Graphql version

graphql: "^16.7.1",
@apollo/server: "^4.7.5",

NestJS version

10.0.3

Node.js version

18.17.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@silto
Copy link
Author

silto commented Mar 7, 2024

I can but I would need to drop the graphql types (GraphQLScalarLiteralParser, GraphQLScalarValueParser,...) and use K | null | undefined. Is that ok?

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

No branches or pull requests

2 participants