From 98a2267c7d6142b2352ab79689230740558fcdb4 Mon Sep 17 00:00:00 2001 From: Iddan Aaronsohn Date: Wed, 23 Jun 2021 20:17:56 +0300 Subject: [PATCH] docs: add jsdoc for $settings (#90) Co-authored-by: Jason Kuhrt --- src/generator/gentime/settingsSingleton.ts | 16 ++ src/generator/models/declaration.ts | 29 +++ .../__snapshots__/enum.test.ts.snap | 58 +++++ .../__snapshots__/enumDoc.test.ts.snap | 58 +++++ .../modelDocumentation.test.ts.snap | 116 +++++++++ .../modelRelationFields.test.ts.snap | 29 +++ .../modelScalarFields.test.ts.snap | 232 ++++++++++++++++++ 7 files changed, 538 insertions(+) diff --git a/src/generator/gentime/settingsSingleton.ts b/src/generator/gentime/settingsSingleton.ts index 88542a3ff..1bb7f53ee 100644 --- a/src/generator/gentime/settingsSingleton.ts +++ b/src/generator/gentime/settingsSingleton.ts @@ -83,6 +83,22 @@ export namespace Gentime { }, }) + /** + * Adjust Nexus Prisma's [gentime settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + * + * @example + * + * // prisma/nexus-prisma.ts + * + * import { settings } from 'nexus-prisma/generator' + * + * settings({ + * projectIdIntToGraphQL: 'ID', + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_runtime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + */ export function changeSettings(input: Setset.UserInput): void { settings.change(input) } diff --git a/src/generator/models/declaration.ts b/src/generator/models/declaration.ts index 14759d008..1460a347b 100644 --- a/src/generator/models/declaration.ts +++ b/src/generator/models/declaration.ts @@ -130,6 +130,35 @@ export function renderTypeScriptDeclarationForDocumentModels( import { Runtime } from '../generator/runtime/settingsSingleton' + /** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the "db" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings ` + OS.EOL ) diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap index 3d58adc1a..741922292 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/enum.test.ts.snap @@ -120,6 +120,35 @@ export const Foo: $Types.Foo import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -218,6 +247,35 @@ export const Foo: $Types.Foo import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/enumDoc.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/enumDoc.test.ts.snap index de0db9ebc..5b9f3703a 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/enumDoc.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/enumDoc.test.ts.snap @@ -94,6 +94,35 @@ export const Foo: $Types.Foo import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -218,6 +247,35 @@ export const Foo: $Types.Foo import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap index 51a5d0508..decc74645 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelDocumentation.test.ts.snap @@ -170,6 +170,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -356,6 +385,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -516,6 +574,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -702,6 +789,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap index 6df365b60..4d6d8b737 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelRelationFields.test.ts.snap @@ -455,6 +455,35 @@ export const Post: $Types.Post import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap index 092f19744..6872b96fb 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap @@ -233,6 +233,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -470,6 +499,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -707,6 +765,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -944,6 +1031,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -1181,6 +1297,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -1367,6 +1512,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -1604,6 +1778,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `; @@ -1790,6 +1993,35 @@ export const SomeModel: $Types.SomeModel import { Runtime } from '../generator/runtime/settingsSingleton' +/** + * Adjust Nexus Prisma's [runtime settings](https://pris.ly/nexus-prisma/docs/settings/runtime). + * + * + * @example + * + * import { PrismaClient } from '@prisma/client' + * import { ApolloServer } from 'apollo-server' + * import { makeSchema } from 'nexus' + * import { User, Post, $settings } from 'nexus-prisma' + * + * new ApolloServer({ + * schema: makeSchema({ + * types: [], + * }), + * context() { + * return { + * db: new PrismaClient(), // <-- You put Prisma client on the \\"db\\" context property + * } + * }, + * }) + * + * $settings({ + * prismaClientContextField: 'db', // <-- Tell Nexus Prisma + * }) + * + * @remarks This is _different_ than Nexus Prisma's [_gentime_ + * settings](https://pris.ly/nexus-prisma/docs/settings/gentime). + */ export const $settings: typeof Runtime.changeSettings " `;