question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using asNexusMethod for datetime / json (graphql types)

See original GitHub issue

I am trying to implement the types for date(time)/json as suggested in the docs (https://nexusjs.org/docs/api/scalar-type) but for my case they or at least type checking doesn`t seem to work.

I have a single shared.ts file with the following code:

import { interfaceType } from '@nexus/schema'

import { asNexusMethod } from '@nexus/schema'
import { DateTimeResolver, JSONObjectResolver } from 'graphql-scalars'

export const jsonScalar = asNexusMethod(JSONObjectResolver, 'json')
export const dateTimeScalar = asNexusMethod(DateTimeResolver, 'date')

export const SoftDelte = interfaceType({
    name: 'SoftDelete',
    definition(t) {
      t.date('createdAt') // VSCode reports that "date" is unknown
      t.date('updatedAt') // VSCode reports that "date" is unknown
      t.date('deletedAt') // VSCode reports that "date" is unknown

      t.resolveType(() => null)
    },
  })

This is my package.json:

{ "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "ts-node-dev --transpile-only --no-notify api/app.ts", "build": "tsc" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "@nexus/schema": "^0.16.0", "@prisma/client": "^2.9.0", "apollo-server": "^2.18.2", "apollo-server-express": "^2.18.2", "express": "^4.17.1", "graphql": "^15.3.0", "graphql-scalars": "^1.4.0", "nexus-plugin-prisma": "^0.21.0" }, "devDependencies": { "@prisma/cli": "^2.9.0", "ts-node-dev": "^1.0.0-pre.65", "typescript": "^4.0.3" } }

I am running npm run dev while in the code window.

Please help!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jasonkuhrtcommented, Dec 4, 2020

Hey everyone, I don’t think anyone is being rude here, all good. Let’s relax and keep a welcoming atmosphere 😃

Thanks @Sytten looks like some good doc content here indeed.

@TommyCoding About your problems with json typing, if you can share a repo repro with us that would help a lot.

1reaction
tgriessercommented, Dec 4, 2020

I believe this is fixed in 0.19+

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using asNexusMethod for datetime / json (graphql types)
I am trying to implement the types for date(time)/json as suggested in the docs (https://nexusjs.org/docs/api/scalar-type) but for my case ...
Read more >
scalarType - GraphQL Nexus
GraphQL Docs for Scalar Types. Nexus allows you to provide an asNexusMethod property which will make the scalar available as a builtin on...
Read more >
Date and Json in type definition for graphql - Stack Overflow
This Date implementation will parse any string accepted by the Date constructor, and will return the date as a string in ISO format....
Read more >
End-to-end type safety with Next.js, Prisma, and GraphQL
Build a type-safe application with Next.js, GraphQL, and Prisma. ... from 'graphql-scalars' const DateTime = asNexusMethod(DateTimeResolver, ...
Read more >
nexus-prisma - npm
Example: Exposing Prisma Client on GraphQL Context with Apollo Server ... [x] (#8) Support for Prisma Model field types of DateTime & Json...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found