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.

Nexus Schema doesn't compile with scalar types

See original GitHub issue

Unfortunately, I am also having this same problem as was mentioned in Issue 163. I have made a new ticket because the issue still exists although not in the playground or code sandbox environment, which is the reason the previous ticket was closed.

I am trying to follow the documentation on the Nexus-Schema (nexusjs) website for adding scalar types to my GraphQL application.

I have tried adding many of the different implementations to my src/types/Types.ts file using the samples provided in the documentation and the interactive examples. My attempts include:

Without a 3rd party libraries:

const DateScalar = scalarType({
  name: 'Date',
  asNexusMethod: 'date',
  description: 'Date custom scalar type',
  parseValue(value) {
    return new Date(value)
  },
  serialize(value) {
    return value.getTime()
  },
  parseLiteral(ast) {
    if (ast.kind === Kind.INT) {
      return new Date(ast.value)
    }
    return null
  },
})

With graphql-iso-date 3rd party library:

import { GraphQLDate } from 'graphql-iso-date'
export const DateTime = GraphQLDate

With graphql-scalars 3rd party library (as shown in the ghost example):

export const GQLDate = decorateType(GraphQLDate, {
  rootTyping: 'Date',
  asNexusMethod: 'date',
})

I am using this new scalar type in an object definition like the following:

const SomeObject = objectType({
  name: 'SomeObject',
  definition(t) {
    t.date('createdAt') // t.date() is supposed to be available because of `asNexusMethod`
  },
})

In all cases, these types are exported from the types file and imported into the makeSchema’s types property.

import * as types from './types/Types'

console.log("Found types", types)

export const apollo = new ApolloServer({
    schema: makeSchema({
        types,
        ...
    context:()=>(
        ...
    })
})

The console.log statement above does show that consts declared in the types file are in scope:

Found types { 
  GQLDate: Date,
  ...
}

If I run the app in development mode, everything boots up and runs fine.

ts-node-dev --transpile-only ./src/app.ts

However, I encounter errors whenever I try to compile the app to deploy to a server

ts-node ./src/app.ts && tsc

Note: This error occurs occurs running just ts-node ./src/app.ts before it gets to tsc

The errors that shown during the build process are the following:

/Users/user/checkouts/project/node_modules/ts-node/src/index.ts:500
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/types/SomeObject.ts:11:7 - error TS2339: Property 'date' does not exist on type 'ObjectDefinitionBlock<"SomeObject">'.

11     t.date('createdAt')

Does anyone have any ideas on either:

  • a) How can I work around this error? While long-term solutions are ideal, temporary solutions would also be appreciated.
  • b) Any steps I could follow to debug this error? Or ideas on how get additional information to assist with debugging?

Any assistance would be very much welcomed. Thanks!

These scalar types have been added to makeSchema’s types

I am using the most recent version of @nexus/schema "^0.17.0"

I have also posted this question on stack overflow here: https://stackoverflow.com/questions/64932457/graphql-nexus-schema-nexusjs-doesnt-compile-with-scalar-types

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tgriessercommented, Nov 30, 2020

Are the generated types checked in to source control anywhere? If not can you try adding:

makeSchema({
 // ... rest of your config
 shouldExitAfterGenerateArtifacts: process.argv.includes('--nexusTypegen'),
})

and running:

ts-node --transpile-only ./src/app.ts --nexusTypegen && tsc

and see if that helps? I am working on a script that will hopefully simplify this process, as I know it’s a big pain point.

0reactions
Joel-Ajayicommented, Jun 10, 2022

–nexusTypegen

Thanks, your solution worked for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nexus Schema doesn't compile with scalar types · Issue #690
I am trying to follow the documentation on the Nexus-Schema (nexusjs) website for adding scalar types to my GraphQL application. ... In all...
Read more >
GraphQL Nexus Schema (nexusjs) doesn't compile with ...
The issue seems to be resolved when --transpile-only flag is added to the nexus:reflect command. This means the reflection command gets ...
Read more >
Nexus Schema doesn't compile with scalar types
Nexus Schema doesn't compile with scalar types. ... I have made a new ticket because the issue still exists although not in the...
Read more >
scalarType
scalarType. GraphQL Docs for Scalar Types. Nexus allows you to provide an asNexusMethod property which will make the scalar available as a builtin...
Read more >
Custom scalars - Apollo GraphQL Docs
The GraphQL specification includes default scalar types Int , Float , String , Boolean , and ... To define a custom scalar, add...
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