diff --git a/src/generator/models/declaration.ts b/src/generator/models/declaration.ts index 40efd3f6a..20591bda8 100644 --- a/src/generator/models/declaration.ts +++ b/src/generator/models/declaration.ts @@ -120,11 +120,12 @@ export function fieldTypeToGraphQLType(field: DMMF.Field): LiteralUnion { +export async function generate(content: string): Promise<{ indexjs: string; indexdts: string }> { const schema = createSchema(content) const dmmf = await PrismaSDK.getDMMF({ datamodel: schema, }) - const runtime = generateRuntime(dmmf) + const [indexjs, indexdts] = generateRuntime(dmmf) as [ModuleSpec, ModuleSpec] - return runtime + return { + indexdts: indexdts.content, + indexjs: indexjs.content, + } } export function setupTestProject({ diff --git a/tests/__snapshots__/runtime.test.ts.snap b/tests/__snapshots__/runtime.test.ts.snap deleted file mode 100644 index f88068b61..000000000 --- a/tests/__snapshots__/runtime.test.ts.snap +++ /dev/null @@ -1,531 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`generates static TS code given DMMF 1`] = ` -Array [ - Object { - "content": "const { getPrismaClientDmmf } = require('../helpers/prisma') -const ModelsGenerator = require('../generator/models') - -const dmmf = getPrismaClientDmmf() -const models = ModelsGenerator.JS.createModels(dmmf) - -module.exports = models", - "fileName": "index.js", - }, - Object { - "content": "import * as Nexus from 'nexus' -import * as NexusCore from 'nexus/dist/core' - -// -// Types -// - -declare namespace $Types { - /** - * ### 📔 Missing Model Documentation for \`M1\` - * - * Get JSDoc documentation for this model automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a model add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * /// Lorem ipsum dolor sit amet... - * model M1 { - * id String @id - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * /// A user record. A user maps 1:1 with a person. Not - * /// to be confused with an \`Account\` which on person - * /// may have multiple of, all linked to a single \`User\`. - * model User { - * id String @id - * } - * \`\`\` - */ - interface M1 { - $name: 'M1' - $description: null - /** - * ### 📔 Missing Field Documentation for \`f10\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f10 String - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f10: { - /** - * The name of this field. - */ - name: 'f10' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'ID'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f11\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f11 Int - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f11: { - /** - * The name of this field. - */ - name: 'f11' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'Int'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f12\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f12 Float - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f12: { - /** - * The name of this field. - */ - name: 'f12' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'Float'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f13\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f13 Boolean - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f13: { - /** - * The name of this field. - */ - name: 'f13' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'Boolean'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f14\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f14 Decimal - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f14: { - /** - * The name of this field. - */ - name: 'f14' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'String'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f15\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f15 BigInt - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f15: { - /** - * The name of this field. - */ - name: 'f15' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'String'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f16\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f16 DateTime - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f16: { - /** - * The name of this field. - */ - name: 'f16' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'DateTime'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f17\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f17 Json - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f17: { - /** - * The name of this field. - */ - name: 'f17' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'Json'> - - /** - * The documentation of this field. - */ - description: undefined - } - /** - * ### 📔 Missing Field Documentation for \`f18\` - * - * Get JSDoc documentation for this field automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a field add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model M1 { - * /// Lorem ipsum dolor sit amet. - * f18 Bytes - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * model User { - * /// Identifier for a user. Will never change once set. - * /// More stable than the \`handle\` field which user - * /// _can_ change, but is not human-friendly. Prefer this - * /// for machine consumers but prefer \`handle\` for human - * /// visible things like URL slugs. - * id String @id - * } - * \`\`\` - */ - f18: { - /** - * The name of this field. - */ - name: 'f18' - - /** - * The type of this field. - */ - type: NexusCore.NexusNonNullDef<'String'> - - /** - * The documentation of this field. - */ - description: undefined - } - } -} - - -// -// Exports -// - -/** - * ### 📔 Missing Model Documentation for \`M1\` - * - * Get JSDoc documentation for this model automatically by documenting - * it in your Prisma Schema ✨! - * - * To document a model add a tripple slash comment above it. - * - * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). - * - * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * /// Lorem ipsum dolor sit amet... - * model M1 { - * id String @id - * } - * \`\`\` - * - * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– - * - * \`\`\`prisma - * /// A user record. A user maps 1:1 with a person. Not - * /// to be confused with an \`Account\` which on person - * /// may have multiple of, all linked to a single \`User\`. - * model User { - * id String @id - * } - * \`\`\` - */ -export const M1: $Types.M1", - "fileName": "index.d.ts", - }, -] -`; diff --git a/tests/runtime.test.ts b/tests/runtime.test.ts deleted file mode 100644 index 839ad43c3..000000000 --- a/tests/runtime.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import endent from 'endent' -import { generate } from './__helpers__' - -it('generates static TS code given DMMF', async () => { - const runtime = await generate(endent` - model M1 { - f10 String @id - f11 Int - f12 Float - f13 Boolean - f14 Decimal - f15 BigInt - f16 DateTime - f17 Json - f18 Bytes - } - `) - - expect(runtime).toMatchSnapshot() -}) diff --git a/tests/unit/__snapshots__/jsdoc.test.ts.snap b/tests/unit/__snapshots__/jsdoc.test.ts.snap new file mode 100644 index 000000000..43144af2a --- /dev/null +++ b/tests/unit/__snapshots__/jsdoc.test.ts.snap @@ -0,0 +1,442 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`When a model field has a documentation comment, then it is used for the JSDoc of that field and its $description field 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * Some documentation + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: string + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`When a model field has no documentation comment, then it gets the default JSDoc and its description field is null 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`When a model has a documentation comment, then it is used for the JSDoc of that model and its $description field 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * Some documentation + */ + interface SomeModel { + $name: 'SomeModel' + $description: 'Some documentation' + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * Some documentation + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`When a model has no documentation comment, then it gets the default JSDoc and its description field is null 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; diff --git a/tests/unit/__snapshots__/scalars.test.ts.snap b/tests/unit/__snapshots__/scalars.test.ts.snap new file mode 100644 index 000000000..57d93c42f --- /dev/null +++ b/tests/unit/__snapshots__/scalars.test.ts.snap @@ -0,0 +1,1158 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`A model field with type Boolean maps to GraphQL Boolean scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + /** + * ### 📔 Missing Field Documentation for \`foo\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo Boolean + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'Boolean'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type DateTime maps to GraphQL DateTime custom scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + /** + * ### 📔 Missing Field Documentation for \`foo\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo DateTime + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'DateTime'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type Float maps to GraphQL Float scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + /** + * ### 📔 Missing Field Documentation for \`foo\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo Float + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'Float'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type Int maps to GraphQL Int scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + /** + * ### 📔 Missing Field Documentation for \`foo\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo Int + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'Int'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type Int, attribute @id, maps to GraphQL ID scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id Int + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type Json maps to GraphQL Json custom scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + /** + * ### 📔 Missing Field Documentation for \`foo\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo Json + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'Json'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; + +exports[`A model field with type String, attribute @id, maps to GraphQL ID scalar 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// Types +// + +declare namespace $Types { + /** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ + interface SomeModel { + $name: 'SomeModel' + $description: null + /** + * ### 📔 Missing Field Documentation for \`id\` + * + * Get JSDoc documentation for this field automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a field add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * model User { + * /// Identifier for a user. Will never change once set. + * /// More stable than the \`handle\` field which user + * /// _can_ change, but is not human-friendly. Prefer this + * /// for machine consumers but prefer \`handle\` for human + * /// visible things like URL slugs. + * id String @id + * } + * \`\`\` + */ + id: { + /** + * The name of this field. + */ + name: 'id' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'ID'> + + /** + * The documentation of this field. + */ + description: undefined + } + } +} + + +// +// Exports +// + +/** + * ### 📔 Missing Model Documentation for \`SomeModel\` + * + * Get JSDoc documentation for this model automatically by documenting + * it in your Prisma Schema ✨! + * + * To document a model add a tripple slash comment above it. + * + * Learn more about Prisma Schema comments [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * #### ––––––––––––––––––––––––– Example 1 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * id String @id + * } + * \`\`\` + * + * #### ––––––––––––––––––––––––– Example 2 ––––––––––––––––––––––––– + * + * \`\`\`prisma + * /// A user record. A user maps 1:1 with a person. Not + * /// to be confused with an \`Account\` which on person + * /// may have multiple of, all linked to a single \`User\`. + * model User { + * id String @id + * } + * \`\`\` + */ +export const SomeModel: $Types.SomeModel" +`; diff --git a/tests/unit/customScalarsModule.test.ts b/tests/unit/customScalarsModule.test.ts new file mode 100644 index 000000000..109b2c56b --- /dev/null +++ b/tests/unit/customScalarsModule.test.ts @@ -0,0 +1,23 @@ +import NexusPrismaScalars, * as NexusPrismaScalarsNS from '../../scalars' +import { assertBuildPresent } from '../__helpers__' + +assertBuildPresent() + +it('scalars can be accessed via namespace import', () => { + expect(Object.keys(NexusPrismaScalarsNS)).toMatchInlineSnapshot(` + Array [ + "DateTime", + "Json", + "default", + ] + `) +}) + +it('scalars can be accessed via a default import', () => { + expect(Object.keys(NexusPrismaScalars)).toMatchInlineSnapshot(` + Array [ + "DateTime", + "Json", + ] + `) +}) diff --git a/tests/unit/jsdoc.test.ts b/tests/unit/jsdoc.test.ts new file mode 100644 index 000000000..953e69f91 --- /dev/null +++ b/tests/unit/jsdoc.test.ts @@ -0,0 +1,43 @@ +import { generate } from '../__helpers__' + +it('When a model has no documentation comment, then it gets the default JSDoc and its description field is null', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('When a model field has no documentation comment, then it gets the default JSDoc and its description field is null', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('When a model has a documentation comment, then it is used for the JSDoc of that model and its $description field', async () => { + const { indexdts } = await generate(` + /// Some documentation + model SomeModel { + id String @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('When a model field has a documentation comment, then it is used for the JSDoc of that field and its $description field', async () => { + const { indexdts } = await generate(` + model SomeModel { + /// Some documentation + id String @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) diff --git a/tests/unit/scalars.test.ts b/tests/unit/scalars.test.ts index 109b2c56b..20b2082a8 100644 --- a/tests/unit/scalars.test.ts +++ b/tests/unit/scalars.test.ts @@ -1,23 +1,76 @@ -import NexusPrismaScalars, * as NexusPrismaScalarsNS from '../../scalars' -import { assertBuildPresent } from '../__helpers__' - -assertBuildPresent() - -it('scalars can be accessed via namespace import', () => { - expect(Object.keys(NexusPrismaScalarsNS)).toMatchInlineSnapshot(` - Array [ - "DateTime", - "Json", - "default", - ] +import { generate } from '../__helpers__' + +it('A model field with type String, attribute @id, maps to GraphQL ID scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('A model field with type Int, attribute @id, maps to GraphQL ID scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id Int @id + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('A model field with type Int maps to GraphQL Int scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + foo Int + } `) + + expect(indexdts).toMatchSnapshot() }) -it('scalars can be accessed via a default import', () => { - expect(Object.keys(NexusPrismaScalars)).toMatchInlineSnapshot(` - Array [ - "DateTime", - "Json", - ] +it('A model field with type Float maps to GraphQL Float scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + foo Float + } `) + + expect(indexdts).toMatchSnapshot() +}) + +it('A model field with type Boolean maps to GraphQL Boolean scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + foo Boolean + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('A model field with type Json maps to GraphQL Json custom scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + foo Json + } + `) + + expect(indexdts).toMatchSnapshot() +}) + +it('A model field with type DateTime maps to GraphQL DateTime custom scalar', async () => { + const { indexdts } = await generate(` + model SomeModel { + id String @id + foo DateTime + } + `) + + expect(indexdts).toMatchSnapshot() })