From 0e121120d3c58cf7ecedf9e44ca00904092dcbbf Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:14:08 +0000 Subject: [PATCH 01/17] refactor: code cleanups --- src/cli/nexus-prisma.ts | 31 +++++++--- src/helpers/prismaExternalToInternalDMMF.ts | 68 ++------------------- 2 files changed, 27 insertions(+), 72 deletions(-) diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index 2074e7239..aabea9f77 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -2,20 +2,25 @@ /** This script will be run by the prisma generator system. */ -process.env.DEBUG_COLORS = 'true' -process.env.DEBUG_HIDE_DATE = 'true' -import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' import dindist from 'dindist' import expandTilde from 'expand-tilde' import * as Path from 'path' + +// @ts-expect-error Private api +import * as PrismaClientGenerator from '@prisma/client/generator-build' +import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' + import { generateRuntimeAndEmit } from '../generator' -import { loadUserGentimeSettings, supportedSettingsModulePaths } from '../generator/gentime/settingsLoader' import { Gentime } from '../generator/gentime' +import { loadUserGentimeSettings, supportedSettingsModulePaths } from '../generator/gentime/settingsLoader' import { d } from '../helpers/debugNexusPrisma' import { externalToInternalDmmf } from '../helpers/prismaExternalToInternalDMMF' import { resolveGitHubActionsWindowsPathTilde } from '../helpers/utils' import { renderCodeBlock, renderList, renderWarning } from '../lib/diagnostic' +process.env.DEBUG_COLORS = 'true' +process.env.DEBUG_HIDE_DATE = 'true' + // todo by default error in ci and warn in local // enforceValidPeerDependencies({ // packageJson: require('../../package.json'), @@ -71,14 +76,20 @@ generatorHandler({ ) } - // WARNING: Make sure this logic comes before `loadUserGentimeSettings` below - // otherwise we will overwrite the user's choice for this setting if they have set it. + /** + * Set the place to import Prisma Client from to be whatever has been set as the output in their PSL schema. + * + * WARNING: Make sure this logic comes before `loadUserGentimeSettings` below + * otherwise we will overwrite the user's choice for this setting if they have set it. + */ Gentime.settings.change({ prismaClientImportId: getPrismaClientImportIdForItsGeneratorOutputConfig(prismaClientGenerator), }) - const internalDMMF = externalToInternalDmmf(dmmf) - + /** + * Loading the gentime settings will mutate the gentime settings assuming the user has + * imported and used the gentime settings in their configuration module. + */ loadUserGentimeSettings() /** @@ -95,7 +106,9 @@ generatorHandler({ }) } - generateRuntimeAndEmit(internalDMMF, Gentime.settings) + const prismaClientDmmf = externalToInternalDmmf(dmmf) + + generateRuntimeAndEmit(prismaClientDmmf, Gentime.settings) process.stdout.write( `You can now start using Nexus Prisma in your code. Reference: https://pris.ly/d/nexus-prisma\n` diff --git a/src/helpers/prismaExternalToInternalDMMF.ts b/src/helpers/prismaExternalToInternalDMMF.ts index d17aba566..42342b27f 100644 --- a/src/helpers/prismaExternalToInternalDMMF.ts +++ b/src/helpers/prismaExternalToInternalDMMF.ts @@ -1,65 +1,7 @@ -/* eslint-disable */ -/** - * This module is pulled out of @prisma/client codebase. - * - * TODO Ask client team to expose this helper function from @prisma/client - */ - +// @ts-expect-error Private api +import * as PrismaClientGenerator from '@prisma/client/generator-build' import { DMMF, DMMF as ExternalDMMF } from '@prisma/generator-helper' -import { capitalize, lowerCase } from 'lodash' -import pluralize from 'pluralize' - -export function getCountAggregateOutputName(modelName: string): string { - return `${capitalize(modelName)}CountAggregateOutputType` -} - -/** - * Turns type: string into type: string[] for all args in order to support union input types. - * - * @param document - */ -export function externalToInternalDmmf(document: ExternalDMMF.Document): DMMF.Document { - return { - ...document, - mappings: getMappings(document.mappings, document.datamodel), - } -} - -function getMappings(mappings: ExternalDMMF.Mappings, datamodel: DMMF.Datamodel): DMMF.Mappings { - const modelOperations = mappings.modelOperations - .filter((mapping) => { - const model = datamodel.models.find((m) => m.name === mapping.model) - if (!model) { - throw new Error(`Mapping without model ${mapping.model}`) - } - return model.fields.some((f) => f.kind !== 'object') - }) - .map((mapping: any) => ({ - model: mapping.model, - plural: pluralize(lowerCase(mapping.model)), - findUnique: mapping.findUnique || mapping.findSingle, - findFirst: mapping.findFirst, - findMany: mapping.findMany, - create: mapping.createOne || mapping.createSingle || mapping.create, - createMany: mapping.createMany, - delete: mapping.deleteOne || mapping.deleteSingle || mapping.delete, - update: mapping.updateOne || mapping.updateSingle || mapping.update, - deleteMany: mapping.deleteMany, - updateMany: mapping.updateMany, - upsert: mapping.upsertOne || mapping.upsertSingle || mapping.upsert, - aggregate: mapping.aggregate, - groupBy: mapping.groupBy, - })) - - return { - modelOperations, - otherOperations: mappings.otherOperations, - } -} -export interface BaseField { - name: string - type: string | DMMF.SchemaEnum | DMMF.OutputType | DMMF.SchemaArg - isList: boolean - isRequired: boolean -} +export const externalToInternalDmmf = PrismaClientGenerator.externalToInternalDmmf as ( + document: ExternalDMMF.Document +) => DMMF.Document From c81639d46a7321db729de58d5b442c128705ad2b Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:19:12 +0000 Subject: [PATCH 02/17] fix lint failures --- src/cli/nexus-prisma.ts | 1 - src/helpers/prismaExternalToInternalDMMF.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index aabea9f77..61bfe56cd 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -7,7 +7,6 @@ import expandTilde from 'expand-tilde' import * as Path from 'path' // @ts-expect-error Private api -import * as PrismaClientGenerator from '@prisma/client/generator-build' import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' import { generateRuntimeAndEmit } from '../generator' diff --git a/src/helpers/prismaExternalToInternalDMMF.ts b/src/helpers/prismaExternalToInternalDMMF.ts index 42342b27f..b3882d7fa 100644 --- a/src/helpers/prismaExternalToInternalDMMF.ts +++ b/src/helpers/prismaExternalToInternalDMMF.ts @@ -2,6 +2,7 @@ import * as PrismaClientGenerator from '@prisma/client/generator-build' import { DMMF, DMMF as ExternalDMMF } from '@prisma/generator-helper' +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access export const externalToInternalDmmf = PrismaClientGenerator.externalToInternalDmmf as ( document: ExternalDMMF.Document ) => DMMF.Document From dcc0d01d8487feb99fbee709b98dcd07a29a58df Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:23:23 +0000 Subject: [PATCH 03/17] fix lint error --- src/cli/nexus-prisma.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index 61bfe56cd..3b50fbff4 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -6,7 +6,6 @@ import dindist from 'dindist' import expandTilde from 'expand-tilde' import * as Path from 'path' -// @ts-expect-error Private api import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' import { generateRuntimeAndEmit } from '../generator' From c0576745a7550393f6dcf348aa64cbb1672efc71 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:36:53 +0000 Subject: [PATCH 04/17] fix, scalars module only has named exports --- src/entrypoints/scalars.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/entrypoints/scalars.ts b/src/entrypoints/scalars.ts index d41add3eb..1874950e9 100644 --- a/src/entrypoints/scalars.ts +++ b/src/entrypoints/scalars.ts @@ -1,9 +1,3 @@ -import { BigInt } from '../scalars/BigInt' -import { Bytes } from '../scalars/Bytes' -import { DateTime } from '../scalars/DateTime' -import { Decimal } from '../scalars/Decimal' -import { Json } from '../scalars/Json' - /** * Predefined Nexus scalar type definitions to satisfy all custom scalars needed in GraphQL to map to the * native scalars in Prisma. The mapping is as follows: @@ -75,14 +69,11 @@ import { Json } from '../scalars/Json' * names in Prisma. Then, you are expected to define those custom scalar types in your GraphQL * API. For convenience you can use these ones. */ -const NexusPrismaScalars = { - BigInt, - Bytes, - DateTime, - Decimal, - Json, -} -export default NexusPrismaScalars +import { BigInt } from '../scalars/BigInt' +import { Bytes } from '../scalars/Bytes' +import { DateTime } from '../scalars/DateTime' +import { Decimal } from '../scalars/Decimal' +import { Json } from '../scalars/Json' export { BigInt, Bytes, DateTime, Decimal, Json } From bddd7f34e6b80eb06d46854798003c26b0485224 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:39:55 +0000 Subject: [PATCH 05/17] fix test --- tests/integration/json.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/json.test.ts b/tests/integration/json.test.ts index a05508071..326346c02 100644 --- a/tests/integration/json.test.ts +++ b/tests/integration/json.test.ts @@ -1,7 +1,8 @@ import dedent from 'dindist' import gql from 'graphql-tag' import { list, objectType, queryType } from 'nexus' -import NexusPrismaScalars from '../../src/entrypoints/scalars' + +import * as NexusPrismaScalars from '../../src/entrypoints/scalars' import { testIntegration } from '../__helpers__/testers' testIntegration({ From 476d8b899e6833e7b4defdce82e44991a1c7b469 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:50:25 +0000 Subject: [PATCH 06/17] fix test --- tests/unit/graphqlSchema/json.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/unit/graphqlSchema/json.test.ts b/tests/unit/graphqlSchema/json.test.ts index e861c5cca..fab56afbe 100644 --- a/tests/unit/graphqlSchema/json.test.ts +++ b/tests/unit/graphqlSchema/json.test.ts @@ -1,6 +1,7 @@ import dedent from 'dindist' import { objectType } from 'nexus' -import NexusPrismaScalars from '../../../src/entrypoints/scalars' + +import * as NexusPrismaScalars from '../../../src/entrypoints/scalars' import { testGraphqlSchema } from '../../__helpers__/testers' testGraphqlSchema({ From 0ee6fa5a34526bae09adbe7509438e0f6e024649 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 02:58:23 +0000 Subject: [PATCH 07/17] update test --- tests/unit/customScalarsModule.test.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/unit/customScalarsModule.test.ts b/tests/unit/customScalarsModule.test.ts index 23b12ea91..d4d487954 100644 --- a/tests/unit/customScalarsModule.test.ts +++ b/tests/unit/customScalarsModule.test.ts @@ -1,4 +1,4 @@ -import NexusPrismaScalars, * as NexusPrismaScalarsNS from '../../src/entrypoints/scalars' +import * as NexusPrismaScalarsNS from '../../src/entrypoints/scalars' import { assertBuildPresent } from '../__helpers__/helpers' assertBuildPresent() @@ -15,15 +15,3 @@ Array [ ] `) }) - -it('scalars can be accessed via a default import', () => { - expect(Object.keys(NexusPrismaScalars)).toMatchInlineSnapshot(` - Array [ - "BigInt", - "Bytes", - "DateTime", - "Decimal", - "Json", - ] - `) -}) From 2e31b2b12bb65722590252834ef726322c7d92ea Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 03:03:36 +0000 Subject: [PATCH 08/17] cleanup --- src/cli/nexus-prisma.ts | 4 ++-- .../prisma-utils/externalToInternalDMMF.ts} | 0 src/lib/prisma-utils/index_.ts | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) rename src/{helpers/prismaExternalToInternalDMMF.ts => lib/prisma-utils/externalToInternalDMMF.ts} (100%) diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index 3b50fbff4..9302d8590 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -12,9 +12,9 @@ import { generateRuntimeAndEmit } from '../generator' import { Gentime } from '../generator/gentime' import { loadUserGentimeSettings, supportedSettingsModulePaths } from '../generator/gentime/settingsLoader' import { d } from '../helpers/debugNexusPrisma' -import { externalToInternalDmmf } from '../helpers/prismaExternalToInternalDMMF' import { resolveGitHubActionsWindowsPathTilde } from '../helpers/utils' import { renderCodeBlock, renderList, renderWarning } from '../lib/diagnostic' +import { PrismaUtils } from '../lib/prisma-utils' process.env.DEBUG_COLORS = 'true' process.env.DEBUG_HIDE_DATE = 'true' @@ -104,7 +104,7 @@ generatorHandler({ }) } - const prismaClientDmmf = externalToInternalDmmf(dmmf) + const prismaClientDmmf = PrismaUtils.externalToInternalDmmf(dmmf) generateRuntimeAndEmit(prismaClientDmmf, Gentime.settings) diff --git a/src/helpers/prismaExternalToInternalDMMF.ts b/src/lib/prisma-utils/externalToInternalDMMF.ts similarity index 100% rename from src/helpers/prismaExternalToInternalDMMF.ts rename to src/lib/prisma-utils/externalToInternalDMMF.ts diff --git a/src/lib/prisma-utils/index_.ts b/src/lib/prisma-utils/index_.ts index 29ad0f3a1..74c6a0c3d 100644 --- a/src/lib/prisma-utils/index_.ts +++ b/src/lib/prisma-utils/index_.ts @@ -1,6 +1,9 @@ -import { PrismaClient } from '@prisma/client' import { lowerFirst } from 'lodash' + +import { PrismaClient } from '@prisma/client' + export * from './whereUniqueInput' +export * from './externalToInternalDMMF' /** * Convert a set of Prisma model field names to a TS ORM property name for the WHERE input. From 046870812f15bf1380e809bc8f8d1f556b82fc45 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 03:08:50 +0000 Subject: [PATCH 09/17] update snapshot --- tests/__helpers__/testers.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tests/__helpers__/testers.ts b/tests/__helpers__/testers.ts index f9eafb943..cafd9e2ff 100644 --- a/tests/__helpers__/testers.ts +++ b/tests/__helpers__/testers.ts @@ -1,19 +1,30 @@ -import * as PrismaSDK from '@prisma/sdk' import execa from 'execa' import * as fs from 'fs-jetpack' -import { DocumentNode, execute, ExecutionResult, printSchema } from 'graphql' +import { + DocumentNode, + execute, + ExecutionResult, + printSchema, +} from 'graphql' import { core } from 'nexus' import { AllNexusTypeDefs } from 'nexus/dist/core' +import objectHash from 'object-hash' import * as Path from 'path' +import slug from 'slug' + +import { DMMF } from '@prisma/generator-helper' +import * as PrismaSDK from '@prisma/sdk' + import { generateRuntime } from '../../src/generator/generate' import { Gentime } from '../../src/generator/gentime' import * as ModelsGenerator from '../../src/generator/models' import { Runtime } from '../../src/generator/runtime' -import { ModuleSpec } from '../../src/generator/types' -import { DMMF } from '@prisma/generator-helper' -import slug from 'slug' -import objectHash from 'object-hash' -import { createConsoleLogCapture, createPrismaSchema, prepareGraphQLSDLForSnapshot } from './helpers' +import { Module } from '../../src/generator/types' +import { + createConsoleLogCapture, + createPrismaSchema, + prepareGraphQLSDLForSnapshot, +} from './helpers' /** * Define Nexus type definitions based on the Nexus Prisma configurations @@ -317,9 +328,9 @@ export async function generateModules( }) const [indexjs_esm, indexjs_cjs, indexdts] = generateRuntime(dmmf, Gentime.settings) as [ - ModuleSpec, - ModuleSpec, - ModuleSpec + Module, + Module, + Module ] return { From a36cc56126e554e3461b43eada3364368e8cb43a Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 03:19:13 +0000 Subject: [PATCH 10/17] more fixes --- .../declaration.ts | 48 ++++++++++++------- src/generator/ModuleGenerators/index.ts | 1 + .../index.ts => ModuleGenerators/index_.ts} | 0 .../javascript.ts | 47 +++++++++++------- src/generator/generate.ts | 28 +++++------ src/generator/types.ts | 2 +- tests/__helpers__/testers.ts | 6 +-- .../PrismaClientOnContext.test.ts.snap | 2 +- tests/unit/customScalarsModule.test.ts | 11 +---- 9 files changed, 80 insertions(+), 65 deletions(-) rename src/generator/{models => ModuleGenerators}/declaration.ts (91%) create mode 100644 src/generator/ModuleGenerators/index.ts rename src/generator/{models/index.ts => ModuleGenerators/index_.ts} (100%) rename src/generator/{models => ModuleGenerators}/javascript.ts (95%) diff --git a/src/generator/models/declaration.ts b/src/generator/ModuleGenerators/declaration.ts similarity index 91% rename from src/generator/models/declaration.ts rename to src/generator/ModuleGenerators/declaration.ts index a3eabeba8..a23d53c3d 100644 --- a/src/generator/models/declaration.ts +++ b/src/generator/ModuleGenerators/declaration.ts @@ -1,16 +1,25 @@ -import { DMMF } from '@prisma/generator-helper' import dedent from 'dindist' import * as OS from 'os' import { LiteralUnion } from 'type-fest' -import { StandardGraphQLScalarType, StandardGraphQLScalarTypes } from '../../helpers/graphql' + +import { DMMF } from '@prisma/generator-helper' + +import { + StandardGraphQLScalarType, + StandardGraphQLScalarTypes, +} from '../../helpers/graphql' import { PrismaScalarType } from '../../helpers/prisma' import { allCasesHandled } from '../../helpers/utils' import { PrismaDmmf } from '../../lib/prisma-dmmf' import { Gentime } from '../gentime' -import { jsDocForEnum, jsDocForField, jsDocForModel } from '../helpers/JSDocTemplates' -import { ModuleSpec } from '../types' - -export const createModuleSpec = (dmmf: DMMF.Document, settings: Gentime.Settings.Manager): ModuleSpec => { +import { + jsDocForEnum, + jsDocForField, + jsDocForModel, +} from '../helpers/JSDocTemplates' +import { Module } from '../types' + +export const createModule = (dmmf: DMMF.Document, settings: Gentime.Settings.Manager): Module => { return { fileName: 'index.d.ts', content: dedent` @@ -27,10 +36,10 @@ const NO_MODELS_DEFINED_COMMENT = dedent` // N/A –– You have not defined any models in your Prisma schema file. ` -export function renderTypeScriptDeclarationForDocumentModels( +export const renderTypeScriptDeclarationForDocumentModels = ( dmmf: DMMF.Document, settings: Gentime.Settings.Manager -): string { +): string => { const models = dmmf.datamodel.models const enums = dmmf.datamodel.enums @@ -162,10 +171,10 @@ export function renderTypeScriptDeclarationForDocumentModels( ) } -function renderTypeScriptDeclarationForEnum( +const renderTypeScriptDeclarationForEnum = ( enum_: DMMF.DatamodelEnum, settings: Gentime.Settings.Manager -): string { +): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForEnum({ enum: enum_, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: enum_ }) @@ -178,7 +187,10 @@ function renderTypeScriptDeclarationForEnum( ` } -function renderTypeScriptDeclarationForModel(model: DMMF.Model, settings: Gentime.Settings.Manager): string { +const renderTypeScriptDeclarationForModel = ( + model: DMMF.Model, + settings: Gentime.Settings.Manager +): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForModel({ model, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: model }) @@ -200,16 +212,16 @@ const renderPrismaNodeDocumentationToDescription = (params: { }` } -function renderTypeScriptDeclarationForModelFields( +const renderTypeScriptDeclarationForModelFields = ( model: DMMF.Model, settings: Gentime.Settings.Manager -): string { +): string => { return model.fields .map((field) => renderTypeScriptDeclarationForField({ field, model, settings })) .join('\n') } -function renderTypeScriptDeclarationForField({ +const renderTypeScriptDeclarationForField = ({ field, model, settings, @@ -217,7 +229,7 @@ function renderTypeScriptDeclarationForField({ field: DMMF.Field model: DMMF.Model settings: Gentime.Settings.Manager -}): string { +}): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForField({ field, model, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: field }) return dedent` @@ -245,7 +257,7 @@ function renderTypeScriptDeclarationForField({ ` } -function renderNexusType(field: DMMF.Field, settings: Gentime.Settings.Manager): string { +const renderNexusType = (field: DMMF.Field, settings: Gentime.Settings.Manager): string => { const graphqlType = fieldTypeToGraphQLType(field, settings.data) /** * Relation fields can only work if the related field has been added to the API. @@ -308,10 +320,10 @@ function renderNexusType(field: DMMF.Field, settings: Gentime.Settings.Manager): * @remarks The `settings` param type uses settings data instead of Setset instance because this helper * is used at runtime too where we don't have a Setset instance for gentime. */ -export function fieldTypeToGraphQLType( +export const fieldTypeToGraphQLType = ( field: DMMF.Field, settings: Gentime.Settings.Data -): LiteralUnion { +): LiteralUnion => { // TODO remove once PC is fixed https://prisma-company.slack.com/archives/C016KUHB1R6/p1638816683155000?thread_ts=1638563060.145800&cid=C016KUHB1R6 if (typeof field.type !== 'string') { throw new TypeError(`field.type is supposed to always be a string.`) diff --git a/src/generator/ModuleGenerators/index.ts b/src/generator/ModuleGenerators/index.ts new file mode 100644 index 000000000..25ba20714 --- /dev/null +++ b/src/generator/ModuleGenerators/index.ts @@ -0,0 +1 @@ +export * as ModuleGenerators from './index_' diff --git a/src/generator/models/index.ts b/src/generator/ModuleGenerators/index_.ts similarity index 100% rename from src/generator/models/index.ts rename to src/generator/ModuleGenerators/index_.ts diff --git a/src/generator/models/javascript.ts b/src/generator/ModuleGenerators/javascript.ts similarity index 95% rename from src/generator/models/javascript.ts rename to src/generator/ModuleGenerators/javascript.ts index 08ba50185..5c92c8714 100644 --- a/src/generator/models/javascript.ts +++ b/src/generator/ModuleGenerators/javascript.ts @@ -1,19 +1,30 @@ -import type { DMMF } from '@prisma/client/runtime' import dedent from 'dindist' import { chain } from 'lodash' import * as Nexus from 'nexus' -import { NexusEnumTypeConfig, NexusListDef, NexusNonNullDef, NexusNullDef } from 'nexus/dist/core' -import { MaybePromise, RecordUnknown, Resolver } from '../../helpers/utils' +import { + NexusEnumTypeConfig, + NexusListDef, + NexusNonNullDef, + NexusNullDef, +} from 'nexus/dist/core' +import { inspect } from 'util' + +import type { DMMF } from '@prisma/client/runtime' + +import { + MaybePromise, + RecordUnknown, + Resolver, +} from '../../helpers/utils' +import { Messenger } from '../../lib/messenger' import { PrismaDmmf } from '../../lib/prisma-dmmf' import { PrismaDocumentation } from '../../lib/prisma-documentation' import { PrismaUtils } from '../../lib/prisma-utils' -import { Gentime } from '../gentime' import { createWhereUniqueInput } from '../../lib/prisma-utils/whereUniqueInput' +import { Gentime } from '../gentime' import { Runtime } from '../runtime' -import { ModuleSpec } from '../types' +import { Module } from '../types' import { fieldTypeToGraphQLType } from './declaration' -import { inspect } from 'util' -import { Messenger } from '../../lib/messenger' type PrismaEnumName = string @@ -38,7 +49,7 @@ export type Settings = { /** * Create the module specification for the JavaScript runtime. */ -export function createModuleSpec(params: { +export const createModule = (params: { /** * Resolved generator settings (whatever user supplied merged with defaults). */ @@ -51,7 +62,7 @@ export function createModuleSpec(params: { * Detailed data about the Prisma Schema contents and available operations over its models. */ dmmf: DMMF.Document -}): ModuleSpec { +}): Module => { const { esm, gentimeSettings, dmmf } = params const esmModelExports = @@ -142,10 +153,10 @@ export function createModuleSpec(params: { } } -export function createNexusTypeDefConfigurations( +export const createNexusTypeDefConfigurations = ( dmmf: DMMF.Document, settings: Settings -): NexusTypeDefConfigurations { +): NexusTypeDefConfigurations => { return { ...createNexusObjectTypeDefConfigurations(dmmf, settings), ...createNexusEnumTypeDefConfigurations(dmmf, settings), @@ -169,10 +180,10 @@ type NexusObjectTypeDefConfiguration = Record< /** * Create Nexus object type definition configurations for Prisma models found in the given DMMF. */ -function createNexusObjectTypeDefConfigurations( +const createNexusObjectTypeDefConfigurations = ( dmmf: DMMF.Document, settings: Settings -): NexusObjectTypeDefConfigurations { +): NexusObjectTypeDefConfigurations => { return chain(dmmf.datamodel.models) .map((model) => { return { @@ -206,7 +217,7 @@ const prismaNodeDocumentationToDescription = (params: { // Complex return type I don't really understand how to easily work with manually. // eslint-disable-next-line -export function prismaFieldToNexusType(field: DMMF.Field, settings: Settings) { +export const prismaFieldToNexusType = (field: DMMF.Field, settings: Settings) => { const graphqlType = fieldTypeToGraphQLType(field, settings.gentime) if (field.isList) { @@ -246,11 +257,11 @@ export function prismaFieldToNexusType(field: DMMF.Field, settings: Settings) { * * but this is overall the better way to handle this detail it seems. */ -export function nexusResolverFromPrismaField( +export const nexusResolverFromPrismaField = ( model: DMMF.Model, field: DMMF.Field, settings: Settings -): undefined | Resolver { +): undefined | Resolver => { if (field.kind !== 'object') { return undefined } @@ -374,10 +385,10 @@ type NexusEnumTypeDefConfiguration = AnyNexusEnumTypeConfig /** * Create Nexus enum type definition configurations for Prisma enums found in the given DMMF. */ -function createNexusEnumTypeDefConfigurations( +const createNexusEnumTypeDefConfigurations = ( dmmf: DMMF.Document, settings: Settings -): NexusEnumTypeDefConfigurations { +): NexusEnumTypeDefConfigurations => { return chain(dmmf.datamodel.enums) .map((enum_): AnyNexusEnumTypeConfig => { return { diff --git a/src/generator/generate.ts b/src/generator/generate.ts index df03f9528..ae3ffb427 100644 --- a/src/generator/generate.ts +++ b/src/generator/generate.ts @@ -1,11 +1,13 @@ -import { DMMF } from '@prisma/client/runtime' import * as fs from 'fs-jetpack' import * as Path from 'path' import * as pkgup from 'pkg-up' + +import { DMMF } from '@prisma/client/runtime' + import { d } from '../helpers/debugNexusPrisma' import { Gentime } from './gentime' -import * as ModelsGenerator from './models' -import { ModuleSpec } from './types' +import { ModuleGenerators } from './ModuleGenerators' +import { Module } from './types' const OUTPUT_SOURCE_DIR_ESM = getOutputSourceDir({ esm: true }) const OUTPUT_SOURCE_DIR_CJS = getOutputSourceDir({ esm: false }) @@ -56,13 +58,13 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Se fs.write('dmmf.json', dmmf) } - const declarationSourceFile = ModelsGenerator.TS.createModuleSpec(dmmf, settings) + const declarationSourceFile = ModuleGenerators.TS.createModule(dmmf, settings) if (settings.data.output.directory === 'default') { // ESM const esmSourceFiles = [ - ModelsGenerator.JS.createModuleSpec({ + ModuleGenerators.JS.createModule({ gentimeSettings: settings, esm: true, dmmf, @@ -82,7 +84,7 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Se // CJS const cjsSourceFiles = [ - ModelsGenerator.JS.createModuleSpec({ + ModuleGenerators.JS.createModule({ gentimeSettings: settings, esm: false, dmmf, @@ -100,7 +102,7 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Se }) } else { const sourceFiles = [ - ModelsGenerator.JS.createModuleSpec({ + ModuleGenerators.JS.createModule({ gentimeSettings: settings, esm: false, dmmf, @@ -125,20 +127,18 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Se } /** Transform the given DMMF into JS source code with accompanying TS declarations. */ -export function generateRuntime(dmmf: DMMF.Document, settings: Gentime.Settings.Manager): ModuleSpec[] { - const sourceFiles: ModuleSpec[] = [ - ModelsGenerator.JS.createModuleSpec({ +export const generateRuntime = (dmmf: DMMF.Document, settings: Gentime.Settings.Manager): Module[] => { + return [ + ModuleGenerators.JS.createModule({ gentimeSettings: settings, esm: true, dmmf, }), - ModelsGenerator.JS.createModuleSpec({ + ModuleGenerators.JS.createModule({ gentimeSettings: settings, esm: false, dmmf, }), - ModelsGenerator.TS.createModuleSpec(dmmf, settings), + ModuleGenerators.TS.createModule(dmmf, settings), ] - - return sourceFiles } diff --git a/src/generator/types.ts b/src/generator/types.ts index 0ae9e2360..ca28a738d 100644 --- a/src/generator/types.ts +++ b/src/generator/types.ts @@ -1,4 +1,4 @@ -export type ModuleSpec = { +export type Module = { fileName: string content: string } diff --git a/tests/__helpers__/testers.ts b/tests/__helpers__/testers.ts index cafd9e2ff..01cf2b52e 100644 --- a/tests/__helpers__/testers.ts +++ b/tests/__helpers__/testers.ts @@ -17,7 +17,7 @@ import * as PrismaSDK from '@prisma/sdk' import { generateRuntime } from '../../src/generator/generate' import { Gentime } from '../../src/generator/gentime' -import * as ModelsGenerator from '../../src/generator/models' +import { ModuleGenerators } from '../../src/generator/ModuleGenerators' import { Runtime } from '../../src/generator/runtime' import { Module } from '../../src/generator/types' import { @@ -160,7 +160,7 @@ export const testGraphqlSchema = ( const runtimeSettings = Runtime.Settings.create() const gentimeSettings = Gentime.Settings.create() - const nexusPrisma = ModelsGenerator.JS.createNexusTypeDefConfigurations(dmmf, { + const nexusPrisma = ModuleGenerators.JS.createNexusTypeDefConfigurations(dmmf, { gentime: gentimeSettings.data, runtime: runtimeSettings, }) as any @@ -269,7 +269,7 @@ export const integrationTest = async (params: TestIntegrationParams) => { try { logCap.start() - const nexusPrisma = ModelsGenerator.JS.createNexusTypeDefConfigurations(dmmf, { + const nexusPrisma = ModuleGenerators.JS.createNexusTypeDefConfigurations(dmmf, { runtime: runtimeSettings, gentime: gentimeSettings.data, }) as any diff --git a/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap b/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap index 3d0725fdb..a16a66f67 100644 --- a/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap +++ b/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap @@ -78,7 +78,7 @@ Object { "errors": Array [ [GraphQLError: Could not perform "PrismaClientOnContext" check because there was an error while trying to import Prisma Client: -Error: Cannot find module 'does-not-exist' from 'src/generator/models/javascript.ts'], +Error: Cannot find module 'does-not-exist' from 'src/generator/ModuleGenerators/javascript.ts'], ], } `; diff --git a/tests/unit/customScalarsModule.test.ts b/tests/unit/customScalarsModule.test.ts index d4d487954..fea7a87ec 100644 --- a/tests/unit/customScalarsModule.test.ts +++ b/tests/unit/customScalarsModule.test.ts @@ -4,14 +4,5 @@ import { assertBuildPresent } from '../__helpers__/helpers' assertBuildPresent() it('scalars can be accessed via namespace import', () => { - expect(Object.keys(NexusPrismaScalarsNS)).toMatchInlineSnapshot(` -Array [ - "BigInt", - "Bytes", - "DateTime", - "Decimal", - "Json", - "default", -] -`) + expect(Object.keys(NexusPrismaScalarsNS)).toEqual(['BigInt', 'Bytes', 'DateTime', 'Decimal', 'Json']) }) From b3528fa0c9c369eb851759d1970d4e363424dee4 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:02:51 +0000 Subject: [PATCH 11/17] refactors --- src/cli/nexus-prisma.ts | 32 ++++++++----- src/entrypoints/generator.ts | 4 +- src/generator/ModuleGenerators/declaration.ts | 30 ++++++------ src/generator/ModuleGenerators/javascript.ts | 42 +++++++++-------- src/generator/Settings/Gentime/index.ts | 2 + .../Gentime/loader.ts} | 5 +- .../{gentime => Settings/Gentime}/settings.ts | 0 .../Gentime/singleton.ts} | 0 src/generator/Settings/Runtime/index.ts | 2 + .../{runtime => Settings/Runtime}/settings.ts | 0 .../Runtime/singleton.ts} | 0 src/generator/Settings/index.ts | 1 + src/generator/Settings/index_.ts | 2 + src/generator/generate.ts | 8 ++-- src/generator/gentime/index.ts | 1 - src/generator/gentime/index_.ts | 2 - src/generator/helpers/JSDocTemplates.ts | 46 ++++++++++--------- src/generator/{ => helpers}/types.ts | 0 src/generator/runtime/index.ts | 1 - src/generator/runtime/index_.ts | 2 - tests/__helpers__/testers.ts | 25 +++++----- 21 files changed, 110 insertions(+), 95 deletions(-) create mode 100644 src/generator/Settings/Gentime/index.ts rename src/generator/{gentime/settingsLoader.ts => Settings/Gentime/loader.ts} (96%) rename src/generator/{gentime => Settings/Gentime}/settings.ts (100%) rename src/generator/{gentime/settingsSingleton.ts => Settings/Gentime/singleton.ts} (100%) create mode 100644 src/generator/Settings/Runtime/index.ts rename src/generator/{runtime => Settings/Runtime}/settings.ts (100%) rename src/generator/{runtime/settingsSingleton.ts => Settings/Runtime/singleton.ts} (100%) create mode 100644 src/generator/Settings/index.ts create mode 100644 src/generator/Settings/index_.ts delete mode 100644 src/generator/gentime/index.ts delete mode 100644 src/generator/gentime/index_.ts rename src/generator/{ => helpers}/types.ts (100%) delete mode 100644 src/generator/runtime/index.ts delete mode 100644 src/generator/runtime/index_.ts diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index 9302d8590..3782fd476 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -6,14 +6,24 @@ import dindist from 'dindist' import expandTilde from 'expand-tilde' import * as Path from 'path' -import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' +import { + GeneratorConfig, + generatorHandler, +} from '@prisma/generator-helper' import { generateRuntimeAndEmit } from '../generator' -import { Gentime } from '../generator/gentime' -import { loadUserGentimeSettings, supportedSettingsModulePaths } from '../generator/gentime/settingsLoader' +import { Settings } from '../generator/Settings' +import { + loadUserGentimeSettings, + supportedSettingsModulePaths, +} from '../generator/Settings/Gentime/loader' import { d } from '../helpers/debugNexusPrisma' import { resolveGitHubActionsWindowsPathTilde } from '../helpers/utils' -import { renderCodeBlock, renderList, renderWarning } from '../lib/diagnostic' +import { + renderCodeBlock, + renderList, + renderWarning, +} from '../lib/diagnostic' import { PrismaUtils } from '../lib/prisma-utils' process.env.DEBUG_COLORS = 'true' @@ -49,7 +59,7 @@ generatorHandler({ throw new Error(`Failed to read the custom output path.`) } - Gentime.changeSettings({ + Settings.Gentime.changeSettings({ output: { directory: generator.output.value, }, @@ -80,7 +90,7 @@ generatorHandler({ * WARNING: Make sure this logic comes before `loadUserGentimeSettings` below * otherwise we will overwrite the user's choice for this setting if they have set it. */ - Gentime.settings.change({ + Settings.Gentime.settings.change({ prismaClientImportId: getPrismaClientImportIdForItsGeneratorOutputConfig(prismaClientGenerator), }) @@ -94,19 +104,19 @@ generatorHandler({ * If the output path is some explicit relative path then make it absolute relative to the Prisma Schema file directory. */ if ( - Gentime.settings.data.output.directory !== 'default' && - !Path.isAbsolute(Gentime.settings.data.output.directory) + Settings.Gentime.settings.data.output.directory !== 'default' && + !Path.isAbsolute(Settings.Gentime.settings.data.output.directory) ) { - Gentime.settings.change({ + Settings.Gentime.settings.change({ output: { - directory: Path.join(Path.dirname(schemaPath), Gentime.settings.data.output.directory), + directory: Path.join(Path.dirname(schemaPath), Settings.Gentime.settings.data.output.directory), }, }) } const prismaClientDmmf = PrismaUtils.externalToInternalDmmf(dmmf) - generateRuntimeAndEmit(prismaClientDmmf, Gentime.settings) + generateRuntimeAndEmit(prismaClientDmmf, Settings.Gentime.settings) process.stdout.write( `You can now start using Nexus Prisma in your code. Reference: https://pris.ly/d/nexus-prisma\n` diff --git a/src/entrypoints/generator.ts b/src/entrypoints/generator.ts index 9a141ceaa..3cc6e1528 100644 --- a/src/entrypoints/generator.ts +++ b/src/entrypoints/generator.ts @@ -1,3 +1,3 @@ -import { Gentime } from '../generator/gentime' +import * as GentimeSettings from '../generator/Settings/Gentime' -export const settings = Gentime.changeSettings +export const settings = GentimeSettings.changeSettings diff --git a/src/generator/ModuleGenerators/declaration.ts b/src/generator/ModuleGenerators/declaration.ts index a23d53c3d..77c591464 100644 --- a/src/generator/ModuleGenerators/declaration.ts +++ b/src/generator/ModuleGenerators/declaration.ts @@ -11,15 +11,15 @@ import { import { PrismaScalarType } from '../../helpers/prisma' import { allCasesHandled } from '../../helpers/utils' import { PrismaDmmf } from '../../lib/prisma-dmmf' -import { Gentime } from '../gentime' import { jsDocForEnum, jsDocForField, jsDocForModel, } from '../helpers/JSDocTemplates' -import { Module } from '../types' +import { Module } from '../helpers/types' +import type { Settings } from '../Settings' -export const createModule = (dmmf: DMMF.Document, settings: Gentime.Settings.Manager): Module => { +export const createModule = (dmmf: DMMF.Document, settings: Settings.Gentime.Manager): Module => { return { fileName: 'index.d.ts', content: dedent` @@ -38,7 +38,7 @@ const NO_MODELS_DEFINED_COMMENT = dedent` export const renderTypeScriptDeclarationForDocumentModels = ( dmmf: DMMF.Document, - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager ): string => { const models = dmmf.datamodel.models const enums = dmmf.datamodel.enums @@ -133,10 +133,10 @@ export const renderTypeScriptDeclarationForDocumentModels = ( // // - import { Runtime } from ${ + import type { Settings } from ${ settings.data.output.directory === 'default' - ? `'../generator/runtime'` - : `'nexus-prisma/dist-cjs/generator/runtime'` + ? `'../generator/Settings'` + : `'nexus-prisma/dist-cjs/generator/Settings'` } /** @@ -166,14 +166,14 @@ export const renderTypeScriptDeclarationForDocumentModels = ( * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ - export const $settings: typeof Runtime.changeSettings + export const $settings: Settings.Runtime.Manager['change'] ` + OS.EOL ) } const renderTypeScriptDeclarationForEnum = ( enum_: DMMF.DatamodelEnum, - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager ): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForEnum({ enum: enum_, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: enum_ }) @@ -189,7 +189,7 @@ const renderTypeScriptDeclarationForEnum = ( const renderTypeScriptDeclarationForModel = ( model: DMMF.Model, - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager ): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForModel({ model, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: model }) @@ -204,7 +204,7 @@ const renderTypeScriptDeclarationForModel = ( } const renderPrismaNodeDocumentationToDescription = (params: { - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager node: PrismaDmmf.DocumentableNode }): string => { return `${ @@ -214,7 +214,7 @@ const renderPrismaNodeDocumentationToDescription = (params: { const renderTypeScriptDeclarationForModelFields = ( model: DMMF.Model, - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager ): string => { return model.fields .map((field) => renderTypeScriptDeclarationForField({ field, model, settings })) @@ -228,7 +228,7 @@ const renderTypeScriptDeclarationForField = ({ }: { field: DMMF.Field model: DMMF.Model - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager }): string => { const jsdoc = settings.data.docPropagation.JSDoc ? jsDocForField({ field, model, settings }) + '\n' : '' const description = renderPrismaNodeDocumentationToDescription({ settings, node: field }) @@ -257,7 +257,7 @@ const renderTypeScriptDeclarationForField = ({ ` } -const renderNexusType = (field: DMMF.Field, settings: Gentime.Settings.Manager): string => { +const renderNexusType = (field: DMMF.Field, settings: Settings.Gentime.Manager): string => { const graphqlType = fieldTypeToGraphQLType(field, settings.data) /** * Relation fields can only work if the related field has been added to the API. @@ -322,7 +322,7 @@ const renderNexusType = (field: DMMF.Field, settings: Gentime.Settings.Manager): */ export const fieldTypeToGraphQLType = ( field: DMMF.Field, - settings: Gentime.Settings.Data + settings: Settings.Gentime.Data ): LiteralUnion => { // TODO remove once PC is fixed https://prisma-company.slack.com/archives/C016KUHB1R6/p1638816683155000?thread_ts=1638563060.145800&cid=C016KUHB1R6 if (typeof field.type !== 'string') { diff --git a/src/generator/ModuleGenerators/javascript.ts b/src/generator/ModuleGenerators/javascript.ts index 5c92c8714..29ddd99bc 100644 --- a/src/generator/ModuleGenerators/javascript.ts +++ b/src/generator/ModuleGenerators/javascript.ts @@ -21,11 +21,12 @@ import { PrismaDmmf } from '../../lib/prisma-dmmf' import { PrismaDocumentation } from '../../lib/prisma-documentation' import { PrismaUtils } from '../../lib/prisma-utils' import { createWhereUniqueInput } from '../../lib/prisma-utils/whereUniqueInput' -import { Gentime } from '../gentime' -import { Runtime } from '../runtime' -import { Module } from '../types' +import { Module } from '../helpers/types' +import { Settings } from '../Settings' import { fieldTypeToGraphQLType } from './declaration' +type a = Settings.Runtime.Manager['change'] + type PrismaEnumName = string type PrismaModelName = string @@ -42,8 +43,8 @@ type NexusTypeDefConfigurations = Record< > export type Settings = { - runtime: Runtime.Settings.Manager - gentime: Gentime.Settings.Data + runtime: Settings.Runtime.Manager + gentime: Settings.Gentime.Data } /** @@ -53,7 +54,7 @@ export const createModule = (params: { /** * Resolved generator settings (whatever user supplied merged with defaults). */ - gentimeSettings: Gentime.Settings.Manager + gentimeSettings: Settings.Gentime.Manager /** * Should the module be generated using ESM instead of CJS? */ @@ -69,7 +70,7 @@ export const createModule = (params: { dmmf.datamodel.models .map((model) => { return dedent` - export const ${model.name} = models['${model.name}'] + export const ${model.name} = nexusTypeDefConfigurations['${model.name}'] ` }) .join('\n') || `// N/A -- You have not defined any models in your Prisma Schema.` @@ -78,7 +79,7 @@ export const createModule = (params: { dmmf.datamodel.enums .map((enum_) => { return dedent` - export const ${enum_.name} = models['${enum_.name}'] + export const ${enum_.name} = nexusTypeDefConfigurations['${enum_.name}'] ` }) .join('\n') || `// N/A -- You have not defined any enums in your Prisma Schema.` @@ -91,7 +92,7 @@ export const createModule = (params: { // Static API Exports - export const $settings = Runtime.changeSettings + export const $settings = RuntimeSettings.changeSettings // Reflected Model Exports @@ -103,8 +104,8 @@ export const createModule = (params: { ` : dedent` module.exports = { - $settings: Runtime.changeSettings, - ...models, + $settings: RuntimeSettings.changeSettings, + ...nexusTypeDefConfigurations, } ` @@ -117,13 +118,13 @@ export const createModule = (params: { const imports = esm ? dedent` import { getPrismaClientDmmf } from '${importSpecifierToNexusPrismaSourceDirectory}/helpers/prisma' - import * as ModelsGenerator from '${importSpecifierToNexusPrismaSourceDirectory}/generator/models/index' - import { Runtime } from '${importSpecifierToNexusPrismaSourceDirectory}/generator/runtime/index' + import { ModuleGenerators } from '${importSpecifierToNexusPrismaSourceDirectory}/generator/ModuleGenerators/index' + import * as RuntimeSettings from '${importSpecifierToNexusPrismaSourceDirectory}/generator/Settings/Runtime/index' ` : dedent` const { getPrismaClientDmmf } = require('${importSpecifierToNexusPrismaSourceDirectory}/helpers/prisma') - const ModelsGenerator = require('${importSpecifierToNexusPrismaSourceDirectory}/generator/models/index') - const { Runtime } = require('${importSpecifierToNexusPrismaSourceDirectory}/generator/runtime/index') + const { ModuleGenerators } = require('${importSpecifierToNexusPrismaSourceDirectory}/generator/ModuleGenerators/index') + const RuntimeSettings = require('${importSpecifierToNexusPrismaSourceDirectory}/generator/Settings/Runtime/index') ` return { @@ -132,20 +133,21 @@ export const createModule = (params: { content: dedent` ${imports} - const gentimeSettings = ${JSON.stringify(gentimeSettings.data, null, 2)} + const gentimeSettingsData = ${JSON.stringify(gentimeSettings.data, null, 2)} + const runtimeSettingsManager = RuntimeSettings.settings const dmmf = getPrismaClientDmmf({ // JSON stringify the values to ensure proper escaping // Details: https://github.com/prisma/nexus-prisma/issues/143 // TODO test that fails without this code require: () => require(${JSON.stringify(gentimeSettings.data.prismaClientImportId)}), - importId: gentimeSettings.prismaClientImportId, + importId: gentimeSettingsData.prismaClientImportId, importIdResolved: require.resolve(${JSON.stringify(gentimeSettings.data.prismaClientImportId)}) }) - const models = ModelsGenerator.JS.createNexusTypeDefConfigurations(dmmf, { - runtime: Runtime.settings, - gentime: gentimeSettings, + const nexusTypeDefConfigurations = ModuleGenerators.JS.createNexusTypeDefConfigurations(dmmf, { + gentime: gentimeSettingsData, + runtime: runtimeSettingsManager, }) ${exports} diff --git a/src/generator/Settings/Gentime/index.ts b/src/generator/Settings/Gentime/index.ts new file mode 100644 index 000000000..de6920b6d --- /dev/null +++ b/src/generator/Settings/Gentime/index.ts @@ -0,0 +1,2 @@ +export * from './settings' +export * from './singleton' diff --git a/src/generator/gentime/settingsLoader.ts b/src/generator/Settings/Gentime/loader.ts similarity index 96% rename from src/generator/gentime/settingsLoader.ts rename to src/generator/Settings/Gentime/loader.ts index ee0ac16f0..d7ff1dc7a 100644 --- a/src/generator/gentime/settingsLoader.ts +++ b/src/generator/Settings/Gentime/loader.ts @@ -1,8 +1,9 @@ import * as fs from 'fs' import kleur from 'kleur' import type * as TSNode from 'ts-node' -import { d } from '../../helpers/debugNexusPrisma' -import { renderError } from '../../lib/diagnostic' + +import { d } from '../../../helpers/debugNexusPrisma' +import { renderError } from '../../../lib/diagnostic' export const supportedSettingsModulePaths = [ 'nexus-prisma.ts', diff --git a/src/generator/gentime/settings.ts b/src/generator/Settings/Gentime/settings.ts similarity index 100% rename from src/generator/gentime/settings.ts rename to src/generator/Settings/Gentime/settings.ts diff --git a/src/generator/gentime/settingsSingleton.ts b/src/generator/Settings/Gentime/singleton.ts similarity index 100% rename from src/generator/gentime/settingsSingleton.ts rename to src/generator/Settings/Gentime/singleton.ts diff --git a/src/generator/Settings/Runtime/index.ts b/src/generator/Settings/Runtime/index.ts new file mode 100644 index 000000000..de6920b6d --- /dev/null +++ b/src/generator/Settings/Runtime/index.ts @@ -0,0 +1,2 @@ +export * from './settings' +export * from './singleton' diff --git a/src/generator/runtime/settings.ts b/src/generator/Settings/Runtime/settings.ts similarity index 100% rename from src/generator/runtime/settings.ts rename to src/generator/Settings/Runtime/settings.ts diff --git a/src/generator/runtime/settingsSingleton.ts b/src/generator/Settings/Runtime/singleton.ts similarity index 100% rename from src/generator/runtime/settingsSingleton.ts rename to src/generator/Settings/Runtime/singleton.ts diff --git a/src/generator/Settings/index.ts b/src/generator/Settings/index.ts new file mode 100644 index 000000000..977ba0f62 --- /dev/null +++ b/src/generator/Settings/index.ts @@ -0,0 +1 @@ +export * as Settings from './index_' diff --git a/src/generator/Settings/index_.ts b/src/generator/Settings/index_.ts new file mode 100644 index 000000000..26388f9df --- /dev/null +++ b/src/generator/Settings/index_.ts @@ -0,0 +1,2 @@ +export * as Gentime from './Gentime' +export * as Runtime from './Runtime' diff --git a/src/generator/generate.ts b/src/generator/generate.ts index ae3ffb427..238b2fca3 100644 --- a/src/generator/generate.ts +++ b/src/generator/generate.ts @@ -5,9 +5,9 @@ import * as pkgup from 'pkg-up' import { DMMF } from '@prisma/client/runtime' import { d } from '../helpers/debugNexusPrisma' -import { Gentime } from './gentime' +import { Module } from './helpers/types' import { ModuleGenerators } from './ModuleGenerators' -import { Module } from './types' +import { Settings } from './Settings' const OUTPUT_SOURCE_DIR_ESM = getOutputSourceDir({ esm: true }) const OUTPUT_SOURCE_DIR_CJS = getOutputSourceDir({ esm: false }) @@ -49,7 +49,7 @@ function getOutputSourceDir(params: { esm: boolean }): string { } /** Generate the Nexus Prisma runtime files and emit them into a "hole" in the internal package source tree. */ -export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Settings.Manager): void { +export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Settings.Gentime.Manager): void { d('start generateRuntime with configuration %j', settings) d('start generateRuntime') @@ -127,7 +127,7 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Gentime.Se } /** Transform the given DMMF into JS source code with accompanying TS declarations. */ -export const generateRuntime = (dmmf: DMMF.Document, settings: Gentime.Settings.Manager): Module[] => { +export const generateRuntime = (dmmf: DMMF.Document, settings: Settings.Gentime.Manager): Module[] => { return [ ModuleGenerators.JS.createModule({ gentimeSettings: settings, diff --git a/src/generator/gentime/index.ts b/src/generator/gentime/index.ts deleted file mode 100644 index 5ca59fd0f..000000000 --- a/src/generator/gentime/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as Gentime from './index_' diff --git a/src/generator/gentime/index_.ts b/src/generator/gentime/index_.ts deleted file mode 100644 index 87742f994..000000000 --- a/src/generator/gentime/index_.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * as Settings from './settings' -export * from './settingsSingleton' diff --git a/src/generator/helpers/JSDocTemplates.ts b/src/generator/helpers/JSDocTemplates.ts index 73422ceaa..b02872f99 100644 --- a/src/generator/helpers/JSDocTemplates.ts +++ b/src/generator/helpers/JSDocTemplates.ts @@ -1,14 +1,16 @@ -import { DMMF } from '@prisma/client/runtime' import dedent from 'dindist' + +import { DMMF } from '@prisma/client/runtime' + import { PrismaDocumentation } from '../../lib/prisma-documentation' -import { Gentime } from '../gentime' +import type { Settings } from '../Settings' type JSDoc = string type FieldModelParams = { field: DMMF.Field model: DMMF.Model - settings: Gentime.Settings.Manager + settings: Settings.Gentime.Manager } const jsdocIndent = ' ' @@ -18,10 +20,10 @@ const jsdocEmptyLine = `\n${jsdocIndent}*\n` * Enum */ -export function jsDocForEnum(params: { +export const jsDocForEnum = (params: { enum: DMMF.DatamodelEnum - settings: Gentime.Settings.Manager -}): JSDoc { + settings: Settings.Gentime.Manager +}): JSDoc => { const sections = [ enumIntro(params.enum), nodeDocumentation({ @@ -35,13 +37,13 @@ export function jsDocForEnum(params: { return jsdoc } -function enumIntro(enum_: DMMF.DatamodelEnum): string { +const enumIntro = (enum_: DMMF.DatamodelEnum): string => { return dedent` * Generated Nexus \`enumType\` configuration based on your Prisma schema's enum \`${enum_.name}\`. ` } -function enumExample(enum_: DMMF.DatamodelEnum): string { +const enumExample = (enum_: DMMF.DatamodelEnum): string => { return dedent` * @example * @@ -52,7 +54,7 @@ function enumExample(enum_: DMMF.DatamodelEnum): string { ` } -function enumMissingDocGuide(enum_: DMMF.DatamodelEnum): string { +const enumMissingDocGuide = (enum_: DMMF.DatamodelEnum): string => { return dedent` ${missingDocsIntro({ kind: 'enum', enum: enum_ })} * @@ -71,13 +73,13 @@ function enumMissingDocGuide(enum_: DMMF.DatamodelEnum): string { * Model */ -export function jsDocForModel(params: { model: DMMF.Model; settings: Gentime.Settings.Manager }): JSDoc { +export const jsDocForModel = (params: { model: DMMF.Model; settings: Settings.Gentime.Manager }): JSDoc => { const sections = [modelIntro(params.model), nodeDocumentation(params), modelExample(params.model)] const jsdoc = jsDocBookends(joinSections(sections)) return jsdoc } -function modelIntro(model: DMMF.Model): string { +const modelIntro = (model: DMMF.Model): string => { return dedent` * Generated Nexus \`objectType\` configuration based on your Prisma schema's model \`${model.name}\`. ` @@ -85,9 +87,9 @@ function modelIntro(model: DMMF.Model): string { const nodeDocumentation = ( params: - | { settings: Gentime.Settings.Manager; model: DMMF.Model } - | { settings: Gentime.Settings.Manager; model: DMMF.Model; field: DMMF.Field } - | { settings: Gentime.Settings.Manager; enum: DMMF.DatamodelEnum } + | { settings: Settings.Gentime.Manager; model: DMMF.Model } + | { settings: Settings.Gentime.Manager; model: DMMF.Model; field: DMMF.Field } + | { settings: Settings.Gentime.Manager; enum: DMMF.DatamodelEnum } ): string | null => { const documentation = 'field' in params @@ -119,7 +121,7 @@ const nodeDocumentation = ( return null } -function modelMissingDocGuide(model: DMMF.Model): string { +const modelMissingDocGuide = (model: DMMF.Model): string => { // TODO once https://stackoverflow.com/questions/61893953/how-to-escape-symbol-in-jsdoc-for-vscode // is resolved then we can write better examples below like: id String @id return dedent` @@ -136,7 +138,7 @@ function modelMissingDocGuide(model: DMMF.Model): string { ` } -function modelExample(model: DMMF.Model): string { +const modelExample = (model: DMMF.Model): string => { return dedent` * @example * @@ -157,19 +159,19 @@ function modelExample(model: DMMF.Model): string { * Field */ -export function jsDocForField(params: FieldModelParams): JSDoc { +export const jsDocForField = (params: FieldModelParams): JSDoc => { const sections = [fieldIntro(params), nodeDocumentation(params), fieldExample(params)] const jsdoc = jsDocBookends(joinSections(sections)) return jsdoc } -function fieldIntro({ model, field }: FieldModelParams): string { +const fieldIntro = ({ model, field }: FieldModelParams): string => { return dedent` * Generated Nexus \`t.field\` configuration based on your Prisma schema's model-field \`${model.name}.${field.name}\`. ` } -function fieldMissingDocGuide({ model, field }: FieldModelParams): string { +const fieldMissingDocGuide = ({ model, field }: FieldModelParams): string => { return dedent` ${missingDocsIntro({ kind: 'model', model })} * \`\`\`prisma @@ -183,7 +185,7 @@ function fieldMissingDocGuide({ model, field }: FieldModelParams): string { ` } -function fieldExample({ model, field }: FieldModelParams): string { +const fieldExample = ({ model, field }: FieldModelParams): string => { return dedent` * @example * @@ -204,9 +206,9 @@ function fieldExample({ model, field }: FieldModelParams): string { * Helpers */ -function missingDocsIntro( +const missingDocsIntro = ( info: { kind: 'model'; model: DMMF.Model } | { kind: 'enum'; enum: DMMF.DatamodelEnum } | { kind: 'field' } -): string { +): string => { const thisItem = info.kind === 'enum' ? `enum ${info.enum.name}` diff --git a/src/generator/types.ts b/src/generator/helpers/types.ts similarity index 100% rename from src/generator/types.ts rename to src/generator/helpers/types.ts diff --git a/src/generator/runtime/index.ts b/src/generator/runtime/index.ts deleted file mode 100644 index dc2dca186..000000000 --- a/src/generator/runtime/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * as Runtime from './index_' diff --git a/src/generator/runtime/index_.ts b/src/generator/runtime/index_.ts deleted file mode 100644 index 87742f994..000000000 --- a/src/generator/runtime/index_.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * as Settings from './settings' -export * from './settingsSingleton' diff --git a/tests/__helpers__/testers.ts b/tests/__helpers__/testers.ts index 01cf2b52e..9ab2d83a5 100644 --- a/tests/__helpers__/testers.ts +++ b/tests/__helpers__/testers.ts @@ -16,10 +16,9 @@ import { DMMF } from '@prisma/generator-helper' import * as PrismaSDK from '@prisma/sdk' import { generateRuntime } from '../../src/generator/generate' -import { Gentime } from '../../src/generator/gentime' +import { Module } from '../../src/generator/helpers/types' import { ModuleGenerators } from '../../src/generator/ModuleGenerators' -import { Runtime } from '../../src/generator/runtime' -import { Module } from '../../src/generator/types' +import { Settings } from '../../src/generator/Settings' import { createConsoleLogCapture, createPrismaSchema, @@ -51,8 +50,8 @@ export type IntegrationTestSpec = { /** * Get access to the gentime settings like you would in the gentime config file. */ - nexusPrismaGentimeConfig?(settings: Gentime.Settings.Manager): void - nexusPrismaRuntimeConfig?(settings: Runtime.Settings.Manager): void + nexusPrismaGentimeConfig?(settings: Settings.Gentime.Manager): void + nexusPrismaRuntimeConfig?(settings: Settings.Runtime.Manager): void /** * Access the Prisma Client instance and run some setup side-effects. * @@ -100,12 +99,12 @@ export const testGeneratedModules = (params: { /** * The gentime settings to use. */ - settings?: Gentime.Settings.Input + settings?: Settings.Gentime.Input }) => { it(params.description, async () => { - Gentime.settings.reset() + Settings.Gentime.settings.reset() if (params.settings) { - Gentime.settings.change(params.settings) + Settings.Gentime.settings.change(params.settings) } const { indexdts } = await generateModules(params.databaseSchema) expect(indexdts).toMatchSnapshot('index.d.ts') @@ -157,8 +156,8 @@ export const testGraphqlSchema = ( }), }) - const runtimeSettings = Runtime.Settings.create() - const gentimeSettings = Gentime.Settings.create() + const runtimeSettings = Settings.Runtime.create() + const gentimeSettings = Settings.Gentime.create() const nexusPrisma = ModuleGenerators.JS.createNexusTypeDefConfigurations(dmmf, { gentime: gentimeSettings.data, @@ -241,8 +240,8 @@ export const integrationTest = async (params: TestIntegrationParams) => { await params.setup(prismaClientInternal) } - const runtimeSettings = Runtime.Settings.create() - const gentimeSettings = Gentime.Settings.create() + const runtimeSettings = Settings.Runtime.create() + const gentimeSettings = Settings.Gentime.create() gentimeSettings.change({ prismaClientImportId: prismaClientOutputDirAbsolute, @@ -327,7 +326,7 @@ export async function generateModules( datamodel: prismaSchemaContents, }) - const [indexjs_esm, indexjs_cjs, indexdts] = generateRuntime(dmmf, Gentime.settings) as [ + const [indexjs_esm, indexjs_cjs, indexdts] = generateRuntime(dmmf, Settings.Gentime.settings) as [ Module, Module, Module From 8ea2bfae69f1e83b9d659eff9a29b4045b38257a Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:03:32 +0000 Subject: [PATCH 12/17] format --- src/cli/nexus-prisma.ts | 16 +++------------- src/generator/ModuleGenerators/declaration.ts | 11 ++--------- src/generator/ModuleGenerators/javascript.ts | 13 ++----------- tests/__helpers__/testers.ts | 13 ++----------- 4 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/cli/nexus-prisma.ts b/src/cli/nexus-prisma.ts index 3782fd476..4196fddf1 100755 --- a/src/cli/nexus-prisma.ts +++ b/src/cli/nexus-prisma.ts @@ -6,24 +6,14 @@ import dindist from 'dindist' import expandTilde from 'expand-tilde' import * as Path from 'path' -import { - GeneratorConfig, - generatorHandler, -} from '@prisma/generator-helper' +import { GeneratorConfig, generatorHandler } from '@prisma/generator-helper' import { generateRuntimeAndEmit } from '../generator' import { Settings } from '../generator/Settings' -import { - loadUserGentimeSettings, - supportedSettingsModulePaths, -} from '../generator/Settings/Gentime/loader' +import { loadUserGentimeSettings, supportedSettingsModulePaths } from '../generator/Settings/Gentime/loader' import { d } from '../helpers/debugNexusPrisma' import { resolveGitHubActionsWindowsPathTilde } from '../helpers/utils' -import { - renderCodeBlock, - renderList, - renderWarning, -} from '../lib/diagnostic' +import { renderCodeBlock, renderList, renderWarning } from '../lib/diagnostic' import { PrismaUtils } from '../lib/prisma-utils' process.env.DEBUG_COLORS = 'true' diff --git a/src/generator/ModuleGenerators/declaration.ts b/src/generator/ModuleGenerators/declaration.ts index 77c591464..c7125a386 100644 --- a/src/generator/ModuleGenerators/declaration.ts +++ b/src/generator/ModuleGenerators/declaration.ts @@ -4,18 +4,11 @@ import { LiteralUnion } from 'type-fest' import { DMMF } from '@prisma/generator-helper' -import { - StandardGraphQLScalarType, - StandardGraphQLScalarTypes, -} from '../../helpers/graphql' +import { StandardGraphQLScalarType, StandardGraphQLScalarTypes } from '../../helpers/graphql' import { PrismaScalarType } from '../../helpers/prisma' import { allCasesHandled } from '../../helpers/utils' import { PrismaDmmf } from '../../lib/prisma-dmmf' -import { - jsDocForEnum, - jsDocForField, - jsDocForModel, -} from '../helpers/JSDocTemplates' +import { jsDocForEnum, jsDocForField, jsDocForModel } from '../helpers/JSDocTemplates' import { Module } from '../helpers/types' import type { Settings } from '../Settings' diff --git a/src/generator/ModuleGenerators/javascript.ts b/src/generator/ModuleGenerators/javascript.ts index 29ddd99bc..dc90de10a 100644 --- a/src/generator/ModuleGenerators/javascript.ts +++ b/src/generator/ModuleGenerators/javascript.ts @@ -1,21 +1,12 @@ import dedent from 'dindist' import { chain } from 'lodash' import * as Nexus from 'nexus' -import { - NexusEnumTypeConfig, - NexusListDef, - NexusNonNullDef, - NexusNullDef, -} from 'nexus/dist/core' +import { NexusEnumTypeConfig, NexusListDef, NexusNonNullDef, NexusNullDef } from 'nexus/dist/core' import { inspect } from 'util' import type { DMMF } from '@prisma/client/runtime' -import { - MaybePromise, - RecordUnknown, - Resolver, -} from '../../helpers/utils' +import { MaybePromise, RecordUnknown, Resolver } from '../../helpers/utils' import { Messenger } from '../../lib/messenger' import { PrismaDmmf } from '../../lib/prisma-dmmf' import { PrismaDocumentation } from '../../lib/prisma-documentation' diff --git a/tests/__helpers__/testers.ts b/tests/__helpers__/testers.ts index 9ab2d83a5..81015e89a 100644 --- a/tests/__helpers__/testers.ts +++ b/tests/__helpers__/testers.ts @@ -1,11 +1,6 @@ import execa from 'execa' import * as fs from 'fs-jetpack' -import { - DocumentNode, - execute, - ExecutionResult, - printSchema, -} from 'graphql' +import { DocumentNode, execute, ExecutionResult, printSchema } from 'graphql' import { core } from 'nexus' import { AllNexusTypeDefs } from 'nexus/dist/core' import objectHash from 'object-hash' @@ -19,11 +14,7 @@ import { generateRuntime } from '../../src/generator/generate' import { Module } from '../../src/generator/helpers/types' import { ModuleGenerators } from '../../src/generator/ModuleGenerators' import { Settings } from '../../src/generator/Settings' -import { - createConsoleLogCapture, - createPrismaSchema, - prepareGraphQLSDLForSnapshot, -} from './helpers' +import { createConsoleLogCapture, createPrismaSchema, prepareGraphQLSDLForSnapshot } from './helpers' /** * Define Nexus type definitions based on the Nexus Prisma configurations From 534041e39310208ac7db99cd55b87f4cb6e600da Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:13:05 +0000 Subject: [PATCH 13/17] fixes --- .../ModuleGenerators/{javascript.ts => JS.ts} | 17 ++-- .../{declaration.ts => TS.ts} | 0 src/generator/ModuleGenerators/index_.ts | 4 +- src/generator/generate.ts | 80 +++++++++---------- .../PrismaClientOnContext.test.ts.snap | 2 +- .../__snapshots__/enum.test.ts.snap | 4 +- .../enumDocumentation.test.ts.snap | 16 ++-- .../modelDocumentation.test.ts.snap | 24 +++--- .../modelRelationFields.test.ts.snap | 4 +- .../modelScalarFields.test.ts.snap | 36 ++++----- 10 files changed, 97 insertions(+), 90 deletions(-) rename src/generator/ModuleGenerators/{javascript.ts => JS.ts} (98%) rename src/generator/ModuleGenerators/{declaration.ts => TS.ts} (100%) diff --git a/src/generator/ModuleGenerators/javascript.ts b/src/generator/ModuleGenerators/JS.ts similarity index 98% rename from src/generator/ModuleGenerators/javascript.ts rename to src/generator/ModuleGenerators/JS.ts index dc90de10a..84921b7ca 100644 --- a/src/generator/ModuleGenerators/javascript.ts +++ b/src/generator/ModuleGenerators/JS.ts @@ -1,12 +1,21 @@ import dedent from 'dindist' import { chain } from 'lodash' import * as Nexus from 'nexus' -import { NexusEnumTypeConfig, NexusListDef, NexusNonNullDef, NexusNullDef } from 'nexus/dist/core' +import { + NexusEnumTypeConfig, + NexusListDef, + NexusNonNullDef, + NexusNullDef, +} from 'nexus/dist/core' import { inspect } from 'util' import type { DMMF } from '@prisma/client/runtime' -import { MaybePromise, RecordUnknown, Resolver } from '../../helpers/utils' +import { + MaybePromise, + RecordUnknown, + Resolver, +} from '../../helpers/utils' import { Messenger } from '../../lib/messenger' import { PrismaDmmf } from '../../lib/prisma-dmmf' import { PrismaDocumentation } from '../../lib/prisma-documentation' @@ -14,9 +23,7 @@ import { PrismaUtils } from '../../lib/prisma-utils' import { createWhereUniqueInput } from '../../lib/prisma-utils/whereUniqueInput' import { Module } from '../helpers/types' import { Settings } from '../Settings' -import { fieldTypeToGraphQLType } from './declaration' - -type a = Settings.Runtime.Manager['change'] +import { fieldTypeToGraphQLType } from './TS' type PrismaEnumName = string diff --git a/src/generator/ModuleGenerators/declaration.ts b/src/generator/ModuleGenerators/TS.ts similarity index 100% rename from src/generator/ModuleGenerators/declaration.ts rename to src/generator/ModuleGenerators/TS.ts diff --git a/src/generator/ModuleGenerators/index_.ts b/src/generator/ModuleGenerators/index_.ts index 173034893..7ddc29871 100644 --- a/src/generator/ModuleGenerators/index_.ts +++ b/src/generator/ModuleGenerators/index_.ts @@ -1,2 +1,2 @@ -export * as TS from './declaration' -export * as JS from './javascript' +export * as TS from './TS' +export * as JS from './JS' diff --git a/src/generator/generate.ts b/src/generator/generate.ts index 238b2fca3..a83bf9237 100644 --- a/src/generator/generate.ts +++ b/src/generator/generate.ts @@ -9,47 +9,8 @@ import { Module } from './helpers/types' import { ModuleGenerators } from './ModuleGenerators' import { Settings } from './Settings' -const OUTPUT_SOURCE_DIR_ESM = getOutputSourceDir({ esm: true }) -const OUTPUT_SOURCE_DIR_CJS = getOutputSourceDir({ esm: false }) - -/** - * Find the output source directory. When using the Yalc workflow some additional hacking around is required. - * - * If the Yalc issue https://github.com/wclr/yalc/issues/156 is resolved then this should be as simple as - * using __dirname. - */ -function getOutputSourceDir(params: { esm: boolean }): string { - let outputSourceDir: string - - if (process.env.npm_package_dependencies_nexus_prisma === 'file:.yalc/nexus-prisma') { - const packageJsonFilePath = pkgup.sync() - if (packageJsonFilePath === null) { - throw new Error( - `Nexus Prisma error: Could not find the project root. Project root is the nearest ancestor directory to where this module is running (${__filename}) containing a package.json. Without this information Nexus Prisma does not know where to output its generated code.` - ) - } - outputSourceDir = Path.join( - Path.dirname(packageJsonFilePath), - params.esm ? 'node_modules/nexus-prisma/dist-esm/runtime' : 'node_modules/nexus-prisma/dist-cjs/runtime' - ) - } else { - /** - * At this point in the code we don't know if the CLI running is the CJS or ESM version. - * If it is the CJS version and we're doing an ESM build then we need to adjust the __dirname value. - */ - outputSourceDir = Path.join( - params.esm ? __dirname.replace('dist-cjs', 'dist-esm') : __dirname, - '../runtime' - ) - } - - d(`found outputSourceDir ${outputSourceDir}`) - - return outputSourceDir -} - /** Generate the Nexus Prisma runtime files and emit them into a "hole" in the internal package source tree. */ -export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Settings.Gentime.Manager): void { +export const generateRuntimeAndEmit = (dmmf: DMMF.Document, settings: Settings.Gentime.Manager): void => { d('start generateRuntime with configuration %j', settings) d('start generateRuntime') @@ -126,6 +87,45 @@ export function generateRuntimeAndEmit(dmmf: DMMF.Document, settings: Settings.G d(`done writing all emitted files`) } +/** + * Find the output source directory. When using the Yalc workflow some additional hacking around is required. + * + * If the Yalc issue https://github.com/wclr/yalc/issues/156 is resolved then this should be as simple as + * using __dirname. + */ +const getOutputSourceDir = (params: { esm: boolean }): string => { + let outputSourceDir: string + + if (process.env.npm_package_dependencies_nexus_prisma === 'file:.yalc/nexus-prisma') { + const packageJsonFilePath = pkgup.sync() + if (packageJsonFilePath === null) { + throw new Error( + `Nexus Prisma error: Could not find the project root. Project root is the nearest ancestor directory to where this module is running (${__filename}) containing a package.json. Without this information Nexus Prisma does not know where to output its generated code.` + ) + } + outputSourceDir = Path.join( + Path.dirname(packageJsonFilePath), + params.esm ? 'node_modules/nexus-prisma/dist-esm/runtime' : 'node_modules/nexus-prisma/dist-cjs/runtime' + ) + } else { + /** + * At this point in the code we don't know if the CLI running is the CJS or ESM version. + * If it is the CJS version and we're doing an ESM build then we need to adjust the __dirname value. + */ + outputSourceDir = Path.join( + params.esm ? __dirname.replace('dist-cjs', 'dist-esm') : __dirname, + '../runtime' + ) + } + + d(`found outputSourceDir ${outputSourceDir}`) + + return outputSourceDir +} + +const OUTPUT_SOURCE_DIR_ESM = getOutputSourceDir({ esm: true }) +const OUTPUT_SOURCE_DIR_CJS = getOutputSourceDir({ esm: false }) + /** Transform the given DMMF into JS source code with accompanying TS declarations. */ export const generateRuntime = (dmmf: DMMF.Document, settings: Settings.Gentime.Manager): Module[] => { return [ diff --git a/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap b/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap index a16a66f67..a3f635d04 100644 --- a/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap +++ b/tests/checks/__snapshots__/PrismaClientOnContext.test.ts.snap @@ -78,7 +78,7 @@ Object { "errors": Array [ [GraphQLError: Could not perform "PrismaClientOnContext" check because there was an error while trying to import Prisma Client: -Error: Cannot find module 'does-not-exist' from 'src/generator/ModuleGenerators/javascript.ts'], +Error: Cannot find module 'does-not-exist' from 'src/generator/ModuleGenerators/JS.ts'], ], } `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap index a0f92f64c..f571331d7 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap @@ -91,7 +91,7 @@ export const Foo: Foo // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -120,6 +120,6 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/enumDocumentation.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/enumDocumentation.test.ts.snap index a99ee73ba..fceb8f012 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/enumDocumentation.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/enumDocumentation.test.ts.snap @@ -79,7 +79,7 @@ export const SomeEnum: SomeEnum // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -108,7 +108,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -191,7 +191,7 @@ export const Foo: Foo // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -220,7 +220,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -301,7 +301,7 @@ export const Foo: Foo // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -330,7 +330,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -425,7 +425,7 @@ export const Foo: Foo // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -454,6 +454,6 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap index 12daa8059..81a01b414 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap @@ -123,7 +123,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -152,7 +152,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -291,7 +291,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -320,7 +320,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -470,7 +470,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -499,7 +499,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -637,7 +637,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -666,7 +666,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -816,7 +816,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -845,7 +845,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -968,7 +968,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -997,6 +997,6 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap index 98b5fb9f2..9a1b097c2 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap @@ -391,7 +391,7 @@ export const Post: Post // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -420,6 +420,6 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap index 07bea2fdd..979c3bf30 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap @@ -198,7 +198,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -227,7 +227,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -429,7 +429,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -458,7 +458,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -660,7 +660,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -689,7 +689,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -891,7 +891,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -920,7 +920,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -1122,7 +1122,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -1151,7 +1151,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -1353,7 +1353,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -1382,7 +1382,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -1532,7 +1532,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -1561,7 +1561,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -1763,7 +1763,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -1792,7 +1792,7 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; @@ -1942,7 +1942,7 @@ export const SomeModel: SomeModel // // -import { Runtime } from '../generator/runtime' +import type { Settings } from '../generator/Settings' /** * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). @@ -1971,6 +1971,6 @@ import { Runtime } from '../generator/runtime' * * @remarks This is _different_ than Nexus Prisma's [_gentime_ settings](https://pris.ly/nexus-prisma/docs/settings/gentime). */ -export const $settings: typeof Runtime.changeSettings +export const $settings: Settings.Runtime.Manager['change'] " `; From 8e8afa1bea60652fc44e86eda919a5e258f846bd Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:17:00 +0000 Subject: [PATCH 14/17] tweaks --- src/entrypoints/generator.ts | 4 +--- src/runtimeProxy.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/entrypoints/generator.ts b/src/entrypoints/generator.ts index 3cc6e1528..7d0b9d205 100644 --- a/src/entrypoints/generator.ts +++ b/src/entrypoints/generator.ts @@ -1,3 +1 @@ -import * as GentimeSettings from '../generator/Settings/Gentime' - -export const settings = GentimeSettings.changeSettings +export { changeSettings as settings } from '../generator/Settings/Gentime' diff --git a/src/runtimeProxy.ts b/src/runtimeProxy.ts index 653dd167d..123bf3327 100644 --- a/src/runtimeProxy.ts +++ b/src/runtimeProxy.ts @@ -7,7 +7,7 @@ import { noop } from 'lodash' * This proxy enables users to _not_ get blocked from generating Nexus Prisma. In order to generate Nexus * Prisma they must run Nexus reflection. This in turn means running through code that is using Nexus Prisma. * If we didn't use a proxy, then all that code using Nexus Prisma would not work, unless Nexus Prisma had - * been generated before. Chcicken & Egg situation. + * been generated before. Chicken & Egg situation. * * This solution allows them to do basically anything with Nexus Prisma _before generation_ without hitting * runtime errors. From 9bb9c545e797aa299d52876077a7ff54e475603a Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:17:27 +0000 Subject: [PATCH 15/17] format --- src/generator/ModuleGenerators/JS.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/generator/ModuleGenerators/JS.ts b/src/generator/ModuleGenerators/JS.ts index 84921b7ca..8b9b72846 100644 --- a/src/generator/ModuleGenerators/JS.ts +++ b/src/generator/ModuleGenerators/JS.ts @@ -1,21 +1,12 @@ import dedent from 'dindist' import { chain } from 'lodash' import * as Nexus from 'nexus' -import { - NexusEnumTypeConfig, - NexusListDef, - NexusNonNullDef, - NexusNullDef, -} from 'nexus/dist/core' +import { NexusEnumTypeConfig, NexusListDef, NexusNonNullDef, NexusNullDef } from 'nexus/dist/core' import { inspect } from 'util' import type { DMMF } from '@prisma/client/runtime' -import { - MaybePromise, - RecordUnknown, - Resolver, -} from '../../helpers/utils' +import { MaybePromise, RecordUnknown, Resolver } from '../../helpers/utils' import { Messenger } from '../../lib/messenger' import { PrismaDmmf } from '../../lib/prisma-dmmf' import { PrismaDocumentation } from '../../lib/prisma-documentation' From 6eb62bd1038f0e09ab0dca864e9bb561620b6435 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 04:41:53 +0000 Subject: [PATCH 16/17] accept data loss --- tests/e2e/kitchen-sink.test.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/e2e/kitchen-sink.test.ts b/tests/e2e/kitchen-sink.test.ts index 2e695276d..1571407d6 100644 --- a/tests/e2e/kitchen-sink.test.ts +++ b/tests/e2e/kitchen-sink.test.ts @@ -1,12 +1,16 @@ -import * as Path from 'path' import debug from 'debug' import dindist from 'dindist' import * as Execa from 'execa' import { gql } from 'graphql-request' import * as GQLScalars from 'graphql-scalars' -import { konn, providers } from 'konn' +import { + konn, + providers, +} from 'konn' +import * as Path from 'path' import stripAnsi from 'strip-ansi' import { inspect } from 'util' + import { envarSpecs } from '../../src/lib/peerDepValidator' import { createPrismaSchema } from '../__helpers__/helpers' import { graphQLClient } from '../__providers__/graphqlClient' @@ -76,7 +80,7 @@ beforeEach(() => { build: 'tsc', start: 'node build/server', 'dev:server': 'yarn ts-node-dev --transpile-only server', - 'db:migrate': 'prisma db push --force-reset && ts-node prisma/seed', + 'db:migrate': 'prisma db push --force-reset --accept-data-loss && ts-node prisma/seed', }, dependencies: { dotenv: '^9.0.0', From ce31a7cd3bbd271b3a8a55a19094dad4444d50f3 Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Tue, 1 Feb 2022 18:32:46 +0000 Subject: [PATCH 17/17] format --- tests/e2e/kitchen-sink.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/e2e/kitchen-sink.test.ts b/tests/e2e/kitchen-sink.test.ts index 1571407d6..90400d7f0 100644 --- a/tests/e2e/kitchen-sink.test.ts +++ b/tests/e2e/kitchen-sink.test.ts @@ -3,10 +3,7 @@ import dindist from 'dindist' import * as Execa from 'execa' import { gql } from 'graphql-request' import * as GQLScalars from 'graphql-scalars' -import { - konn, - providers, -} from 'konn' +import { konn, providers } from 'konn' import * as Path from 'path' import stripAnsi from 'strip-ansi' import { inspect } from 'util'