Title
p

Pieter

10/14/2020, 4:31 PM
I'm busy migrating from nexus framework (with prisma plugin) to nexus schema. I can't figure out why
t.date
does not exist. I followed the migration guide.
import { asNexusMethod } from '@nexus/schema'
import { DateTimeResolver } from 'graphql-scalars'

const GQLDate = asNexusMethod(DateTimeResolver, 'date')
GQLDate is in my
types
in
makeSchema
typegenAutoConfig: {
    sources: [
      {
        source: require.resolve('.prisma/client/index.d.ts'),
        alias: 'prisma',
      },
    ],
✔️ 1
@Ryan @jasonkuhrt any idea what I am doing wrong?
a

Ahmed

10/14/2020, 4:33 PM
add this
scalarType({
  name: 'DateTime',
  description: 'Date custom scalar type',
  asNexusMethod: 'date',
  parseValue(value: any) {
    return value ? new Date(value) : null;
  },
  serialize(value: any) {
    return value ? new Date(value) : null;
  },
  parseLiteral(ast: any) {
    return ast.value ? new Date(ast.value) : null;
  },
}),
p

Pieter

10/14/2020, 4:33 PM
but thats what
asNexusMethod
does right?
a

Ahmed

10/14/2020, 4:34 PM
I think but i like this way
p

Pieter

10/14/2020, 4:35 PM
same error
import { scalarType } from '@nexus/schema'
import { DateTimeResolver } from 'graphql-scalars'

const GQLDate = scalarType({
  name: 'DateTime',
  description: 'Date custom scalar type',
  asNexusMethod: 'date',
  parseValue(value: any) {
    return value ? new Date(value) : null
  },
  serialize(value: any) {
    return value ? new Date(value) : null
  },
  parseLiteral(ast: any) {
    return ast.value ? new Date(ast.value) : null
  },
})

export { GQLDate, DateTimeResolver as DateTime }
a

Ahmed

10/14/2020, 4:36 PM
why you adding DateTimeResolver
p

Pieter

10/14/2020, 4:36 PM
export const schema = makeSchema({
  types: [
    GQLDate,
    ...],
  typegenAutoConfig: {
    sources: [
      {
        source: require.resolve('.prisma/client/index.d.ts'),
        alias: 'prisma',
      },
    ],
  },
  plugins: [
    nexusPrisma({
      scalars: {
        DateTime,
        Json,
      },
    }),
  ],
})
exporting it so it can be added to the prisma config as per migration guide
a

Ahmed

10/14/2020, 4:37 PM
if you added my code you don't need to add any other date codes
p

Pieter

10/14/2020, 4:37 PM
so your code will automatically resolve ISO strings into date objects?
I just removed it. same error
a

Ahmed

10/14/2020, 4:38 PM
so your code will automatically resolve ISO strings into date objects?
yes
can you send the error and migration URL?
node_modules/ts-node/src/index.ts:500
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
src/graphql/objectTypes/Company.ts:39:7 - error TS2339: Property 'date' does not exist on type 'ObjectDefinitionBlock<"Usage">'.

39     t.date('from')
a

Ahmed

10/14/2020, 4:46 PM
why you adding DateTime and Json here
plugins: [
    nexusPrisma({
      scalars: {
        DateTime,
        Json,
      },
    }),
p

Pieter

10/14/2020, 4:51 PM
but like I said, same error if I remove it
Any idea?
@Ahmed here's a repo to reproduce https://github.com/cyrus-za/prisma-nexus-date-error
a

Ahmed

10/14/2020, 5:33 PM
yes with this i can see what is issue I will back to you
@Pieter your issue in running command try with this
yarn ts-node --transpile-only index.ts
you missed
--transpile-only
so when you start your command
date
not exist so compiler failed
p

Pieter

10/14/2020, 5:45 PM
Thanks so much! cant believe I missed that
👍 1
a

Ahmed

10/14/2020, 5:46 PM
Don't worry sometimes it will be smaller than this
p

Pieter

10/14/2020, 5:51 PM
Got a new error now but I'll probably be able to figure it out. In case you know top of your head, I figured I'd post it here anyways
You should specify a configuration value for outputs in Nexus' makeSchema. Provide one to remove this warning.
a

Ahmed

10/14/2020, 5:53 PM
It's not erroring just warning you that no output
p

Pieter

10/14/2020, 5:53 PM
ok
How do I get vscode to use the generated types?
{
  "compilerOptions": {
    "allowJs": false,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true,
    "baseUrl": "./",
    "checkJs": false,
    "esModuleInterop": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": false,
    "outDir": "./build",
    "paths": {
      "~/*": [
        "./*",
        "./*/index"
      ]
    },
    "resolveJsonModule": true,
    "rootDir": "./",
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": true,
    "skipLibCheck": true,
    "target": "es2018",
    "typeRoots": [
      "node_modules/@types",
      "types"
    ]
  },
  "exclude": [
    "node_modules",
    "build"
  ],
  "include": [
    "scripts",
    "src",
    "test",
    "types"
  ]
}
should I be adding .prisma/client to typeRoots?
a

Ahmed

10/14/2020, 5:55 PM
no you need to add output for nexus generated types
export const schema = makeSchema({
  types,
// like this 
  outputs: {
    schema: join(process.cwd(), 'src', 'generated', 'schema.graphql'),
    typegen: join(process.cwd(), 'src', 'generated', 'nexus-typegen.ts'),
  },
  typegenAutoConfig: {
    sources: [
      {
        source: require.resolve('./context'),
        alias: 'Context',
      },
    ],
    contextType: 'Context.Context',
  },
})
p

Pieter

10/14/2020, 5:59 PM
also, trying to run the serverless handler throws this
Error! Detecting port 52463 timed out after 300000ms
I got no idea where that port number even comes from.
a

Ahmed

10/14/2020, 6:00 PM
your repo not have any server functions
Oh are you thinking that you will start the GraphQL server from this file
import { makeSchema } from "@nexus/schema";
import { User } from "./User";
import { Query } from "./Query";
import { GQLDate } from "./Date";
import { nexusPrisma } from "nexus-plugin-prisma";

export const schema = makeSchema({
  types: [
    GQLDate,
    Query,
    User,
  ],
   typegenAutoConfig: {
    sources: [
      {
        source: require.resolve('.prisma/client/index.d.ts'),
        alias: 'prisma',
      },
    ]
  },
   plugins: [
    nexusPrisma({
      scalars: {
      // DateTime,
      // Json,
      },
    }),
  ],

});
this just build the schema you need to add server like apollo-server
p

Pieter

10/14/2020, 6:02 PM
ok its probably not nexus related. I'll figure it out. thanks for the help
nope starting it from this file
import { NowRequest, NowResponse } from '@now/node'
import { MIDDLEWARE, server } from '../src/app'
import { map } from 'lodash/fp'
import { RequestHandler } from 'express-serve-static-core'

const handler = server.createHandler()

const runMiddleware = (middleware: RequestHandler): RequestHandler => async (req, res, next) =>
  await middleware(req, res, next)

// export default async (req: NowRequest, res: NowResponse) => {
//   await map(runMiddleware)(MIDDLEWARE)
//   await handler(req, res)
// }

export default handler
and
server
is exported from this file
import logger from '@invisible/logger'
import { flow, includes, pick, toLower } from 'lodash/fp'
import { ApolloServer } from '@saeris/apollo-server-vercel'
import { isAuthenticated } from '../src/middlewares/isAuthenticated'
import { populateUserInfo } from '../src/middlewares/populateUserInfo'
import { requestLogger } from '../src/middlewares/requestLogger'
import { APOLLO_KEY, NODE_ENV } from './config/env'
import { RequestHandler } from 'express-serve-static-core'

import { createContext } from './context'
import { schema } from './graphql'

const apolloServerOptions = {
  context: createContext,
  tracing: NODE_ENV !== 'production',
  schema,
  reportSchema: true,
  introspection: true,
  path: '/api/graphql',
  formatError: (err: Error & any) => {
    const meta = {
      code: err.extensions.code,
      query: err.source?.body,
      ...pick(['name', 'locations', 'path', 'originalError.message'])(err),
    }

    if (flow(toLower, includes('jwt expired'))(err.message)) {
      // Ignore logging JWT Expired errors
    } else if (err.message.startsWith('Warn:')) {
      logger.warn(err.message.substring(0, 255), meta)
    } else {
      logger.error(err.message.substring(0, 255), meta)
    }

    // Otherwise return the original error.  The error can also
    // be manipulated in other ways, so long as it's returned.
    return err
  },
  engine: APOLLO_KEY ? { apiKey: APOLLO_KEY } : undefined,
}

export const server = new ApolloServer(apolloServerOptions)

export const MIDDLEWARE: RequestHandler[] = [isAuthenticated, populateUserInfo, requestLogger]
using
import { ApolloServer } from '@saeris/apollo-server-vercel'
and running with
vc dev
which runs that file
ts-node-dev --transpile-only api/graphql.ts
a

Ahmed

10/14/2020, 6:04 PM
sorry I can't help you in this point
p

Pieter

10/14/2020, 6:04 PM
yep I figured as much 🙂
I forgot to say thanks for the help 🙂
👍 1
a

Ahmed

10/15/2020, 8:24 PM
You are welcome
p

Pieter

10/16/2020, 12:19 AM
I had to pause work on this for a day. Back at it now. Using --transpile-only means it wont throw errors, but I still cannot build my typescript project without running into these errors
turns out I had to configure the
outputs
directory for my types to be generated. this isnt in the migration guide 😕