Pieter
10/14/2020, 4:31 PMt.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',
},
],
Ahmed
10/14/2020, 4:33 PMscalarType({
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;
},
}),
Pieter
10/14/2020, 4:33 PMasNexusMethod
does right?Ahmed
10/14/2020, 4:34 PMPieter
10/14/2020, 4:35 PMimport { 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 }
Ahmed
10/14/2020, 4:36 PMPieter
10/14/2020, 4:36 PMexport const schema = makeSchema({
types: [
GQLDate,
...],
typegenAutoConfig: {
sources: [
{
source: require.resolve('.prisma/client/index.d.ts'),
alias: 'prisma',
},
],
},
plugins: [
nexusPrisma({
scalars: {
DateTime,
Json,
},
}),
],
})
Ahmed
10/14/2020, 4:37 PMPieter
10/14/2020, 4:37 PMAhmed
10/14/2020, 4:38 PMso your code will automatically resolve ISO strings into date objects?yes
Pieter
10/14/2020, 4:43 PMnode_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')
Ahmed
10/14/2020, 4:46 PMplugins: [
nexusPrisma({
scalars: {
DateTime,
Json,
},
}),
Pieter
10/14/2020, 4:51 PMAhmed
10/14/2020, 5:33 PMyarn ts-node --transpile-only index.ts
you missed --transpile-only
so when you start your command date
not exist so compiler failedPieter
10/14/2020, 5:45 PMAhmed
10/14/2020, 5:46 PMPieter
10/14/2020, 5:51 PMYou should specify a configuration value for outputs in Nexus' makeSchema. Provide one to remove this warning.
Ahmed
10/14/2020, 5:53 PMPieter
10/14/2020, 5:53 PM{
"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"
]
}
Ahmed
10/14/2020, 5:55 PMexport 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',
},
})
Pieter
10/14/2020, 5:59 PMError! Detecting port 52463 timed out after 300000ms
I got no idea where that port number even comes from.Ahmed
10/14/2020, 6:00 PMimport { 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-serverPieter
10/14/2020, 6:02 PMimport { 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
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]
import { ApolloServer } from '@saeris/apollo-server-vercel'
vc dev
which runs that filets-node-dev --transpile-only api/graphql.ts
Ahmed
10/14/2020, 6:04 PMPieter
10/14/2020, 6:04 PMAhmed
10/15/2020, 8:24 PMPieter
10/16/2020, 12:19 AMoutputs
directory for my types to be generated. this isnt in the migration guide 😕