From 67ce824a41a36913188b4ff26b2b0732a16c0a43 Mon Sep 17 00:00:00 2001 From: Iddan Aaronsohn Date: Wed, 7 Jul 2021 20:31:35 +0300 Subject: [PATCH] feat: add support for BigInt scalar (#56) Co-authored-by: Jason Kuhrt --- README.md | 17 +- src/entrypoints/scalars.ts | 20 +- src/generator/models/declaration.ts | 16 +- src/helpers/graphql.ts | 2 +- src/scalars/BigInt.ts | 39 +++ tests/e2e/__snapshots__/e2e.test.ts.snap | 26 ++ tests/e2e/e2e.test.ts | 25 +- tests/integration/json.test.ts | 1 + tests/unit/customScalarsModule.test.ts | 16 +- .../__snapshots__/json.test.ts.snap | 6 + tests/unit/graphqlSchema/json.test.ts | 1 + .../modelScalarFields.test.ts.snap | 266 ++++++++++++++++++ .../modelScalarFields.test.ts | 10 + 13 files changed, 413 insertions(+), 32 deletions(-) create mode 100644 src/scalars/BigInt.ts diff --git a/README.md b/README.md index f66459aa5..8fce9dd7f 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ export const schema = makeSchema({ ##### Shortterm -- [ ] ([#59](https://github.com/prisma/nexus-prisma/issues/59)) Support for Prisma Model field type `BigInt` +- [x] ([#59](https://github.com/prisma/nexus-prisma/issues/59)) Support for Prisma Model field type `BigInt` - [ ] ([#94](https://github.com/prisma/nexus-prisma/issues/94)) Support for Prisma Model field type `Decimal` - [ ] Improved JSDoc for relation 1:1 & 1:n fields @@ -221,13 +221,16 @@ However some of the Prisma scalars do not have a natural standard representation **Prisma Standard-Scalar to GraphQL Custom-Scalar Mapping** -| Prisma | GraphQL | Nexus `t` Helper | GraphQL Scalar Implementation | -| ---------- | ---------- | ---------------- | ----------------------------------------------------------------- | -| `Json` | `Json` | `json` | [JsonObject](https://github.com/Urigo/graphql-scalars#jsonobject) | -| `DateTime` | `DateTime` | `dateTime` | [DateTime](https://github.com/Urigo/graphql-scalars#datetime) | -| `Bytes` | `Bytes` | `bytes` | [Bytes](https://www.graphql-scalars.dev/docs/scalars/byte/) | +| Prisma | GraphQL | Nexus `t` Helper | GraphQL Scalar Implementation | Additional Info | +| ---------- | ---------- | ---------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | +| `Json` | `Json` | `json` | [JsonObject](https://www.graphql-scalars.dev/docs/scalars/jsonobject) | | +| `DateTime` | `DateTime` | `dateTime` | [DateTime](https://www.graphql-scalars.dev/docs/scalars/datetime) | | +| `BigInt` | `BigInt` | `bigInt` | [BigInt](https://www.graphql-scalars.dev/docs/scalars/big-int) | [JavaScript BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) | +| `Bytes` | `Bytes` | `bytes` | [Byte](https://www.graphql-scalars.dev/docs/scalars/byte/) | [Node.js Buffer](https://nodejs.org/api/buffer.html#buffer_buffer) | -> **Note:** Not all Prisma scalar mappings are implemented yet: `BigInt`, `Decimal`, `Unsupported` +> **Note:** Not all Prisma scalar mappings are implemented yet: `Decimal`, `Unsupported` + +> **Note:** BigInt is supported in Node.js since version [10.4.0](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#browser_compatibility) however to support BigInt in `JSON.parse`/`JSON.stringify` you must use [`json-bigint-patch`](https://github.com/ardatan/json-bigint-patch) otherwise BigInt values will be serialized as strings. You can use your own GraphQL Scalar Implementation, however, you _must adhear to the above Prisma/GraphQL name mapping defined above_. diff --git a/src/entrypoints/scalars.ts b/src/entrypoints/scalars.ts index 2aa05405a..9ede229c3 100644 --- a/src/entrypoints/scalars.ts +++ b/src/entrypoints/scalars.ts @@ -1,19 +1,22 @@ +import { BigInt } from '../scalars/BigInt' +import { Bytes } from '../scalars/Bytes' import { DateTime } from '../scalars/DateTime' import { Json } from '../scalars/Json' -import { Bytes } from '../scalars/Bytes' /** * 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: * - * | Prisma | GraphQL | Nexus `t` Helper | GraphQL Scalar Implementation | - * | ---------- | ---------- | ---- | ----------------------------------------------------------------- | - * | `Json` | `Json` | `json` | [JsonObject](https://github.com/Urigo/graphql-scalars#jsonobject) | - * | `DateTime` | `DateTime` | `datetime` | [DateTime](https://github.com/Urigo/graphql-scalars#datetime) |. + * | Prisma | GraphQL | Nexus `t` Helper | GraphQL Scalar Implementation | Additional Info | + * | ---------- | ---------- | ---------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | + * | `Json` | `Json` | `json` | [JsonObject](https://www.graphql-scalars.dev/docs/scalars/jsonobject) | | + * | `DateTime` | `DateTime` | `dateTime` | [DateTime](https://www.graphql-scalars.dev/docs/scalars/datetime) | | + * | `BigInt` | `BigInt` | `bigInt` | [BigInt](https://www.graphql-scalars.dev/docs/scalars/big-int) | [JavaScript BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) | + * | `Bytes` | `Bytes` | `bytes` | [Byte](https://www.graphql-scalars.dev/docs/scalars/byte/) | [Node.js Buffer](https://nodejs.org/api/buffer.html#buffer_buffer) | * * @example * - * // Use this defualt export + * // Use this default export * * import { makeSchema, objectType } from 'nexus' * import NexusPrismaScalars from 'nexus-prisma/scalars' @@ -35,7 +38,7 @@ import { Bytes } from '../scalars/Bytes' * * @example * - * // Use only select precefined custom scalars + * // Use only select predefined custom scalars * * import { makeSchema, objectType } from 'nexus' * import { Json } from 'nexus-prisma/scalars' @@ -70,6 +73,7 @@ import { Bytes } from '../scalars/Bytes' * API. For convenience you can use these ones. */ const NexusPrismaScalars = { + BigInt, Bytes, DateTime, Json, @@ -77,4 +81,4 @@ const NexusPrismaScalars = { export default NexusPrismaScalars -export { Bytes, DateTime, Json } +export { BigInt, Bytes, DateTime, Json } diff --git a/src/generator/models/declaration.ts b/src/generator/models/declaration.ts index 1460a347b..606eea445 100644 --- a/src/generator/models/declaration.ts +++ b/src/generator/models/declaration.ts @@ -2,7 +2,7 @@ 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 { StandardGraphQLScalarType, StandardGraphQLScalarTypes } from '../../helpers/graphql' import { PrismaScalarType } from '../../helpers/prisma' import { allCasesHandled } from '../../helpers/utils' import { Gentime } from '../gentime/settingsSingleton' @@ -276,25 +276,25 @@ export function fieldTypeToGraphQLType( if (field.isId) { if (field.type === 'String' || (field.type === 'Int' && settings.projectIdIntToGraphQL === 'ID')) { - return StandardgraphQLScalarTypes.ID + return StandardGraphQLScalarTypes.ID } } switch (typeName) { case 'String': { - return StandardgraphQLScalarTypes.String + return StandardGraphQLScalarTypes.String } case 'Int': { - return StandardgraphQLScalarTypes.Int + return StandardGraphQLScalarTypes.Int } case 'Boolean': { - return StandardgraphQLScalarTypes.Boolean + return StandardGraphQLScalarTypes.Boolean } case 'Float': { - return StandardgraphQLScalarTypes.Float + return StandardGraphQLScalarTypes.Float } case 'BigInt': { - return StandardgraphQLScalarTypes.String + return 'BigInt' } case 'DateTime': { return 'DateTime' @@ -306,7 +306,7 @@ export function fieldTypeToGraphQLType( return 'Bytes' } case 'Decimal': { - return StandardgraphQLScalarTypes.String + return StandardGraphQLScalarTypes.String } default: { return allCasesHandled(typeName) diff --git a/src/helpers/graphql.ts b/src/helpers/graphql.ts index 3c528d078..15ac11eba 100644 --- a/src/helpers/graphql.ts +++ b/src/helpers/graphql.ts @@ -1,6 +1,6 @@ export type StandardGraphQLScalarType = 'ID' | 'String' | 'Int' | 'Float' | 'Boolean' -export const StandardgraphQLScalarTypes = { +export const StandardGraphQLScalarTypes = { ID: 'ID', String: 'String', Float: 'Float', diff --git a/src/scalars/BigInt.ts b/src/scalars/BigInt.ts new file mode 100644 index 000000000..eef11b46f --- /dev/null +++ b/src/scalars/BigInt.ts @@ -0,0 +1,39 @@ +import { GraphQLScalarType } from 'graphql' +import { BigIntResolver } from 'graphql-scalars' +import { asNexusMethod } from 'nexus' + +/** + * A Nexus scalar type definition for the `BigInt` scalar type + * + * Contributes a scalar to your GraphQL schema called `BigInt`. + * + * Contributes a `t` `[1]` helper method called `bigInt` + * + * `[1]` A `t` helper method refers to a method on the argument given to a `definition` method. Helper methods + * here typically help you quickly create new fields. + * + * @example + * + * import { makeSchema, objectType } from 'nexus' + * import { BigInt } from 'nexus-prisma/scalars' + * + * SomeObject = objectType({ + * name: 'SomeObject', + * definition(t) { + * t.bigInt('someBigIntField') + * }, + * }) + * + * makeSchema({ + * types: [BigInt, SomeObject], + * }) + * + */ +export const BigInt = asNexusMethod( + new GraphQLScalarType({ + ...BigIntResolver, + description: `The \`BigInt\` scalar type represents non-fractional signed whole numeric values. +@see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt`, + }), + 'bigInt' +) diff --git a/tests/e2e/__snapshots__/e2e.test.ts.snap b/tests/e2e/__snapshots__/e2e.test.ts.snap index 5707f9124..a23cf93da 100644 --- a/tests/e2e/__snapshots__/e2e.test.ts.snap +++ b/tests/e2e/__snapshots__/e2e.test.ts.snap @@ -5,15 +5,18 @@ Object { "bars": Array [ Object { "foo": Object { + "BigIntManually": null, "BytesManually": null, "DateTimeManually": null, "JsonManually": null, + "someBigIntField": "9007199254740991", "someBytesField": Object { "data": Array [], "type": "Buffer", }, "someDateTimeField": "2021-05-10T20:42:46.609Z", "someEnumA": "alpha", + "someJsonField": Object {}, }, }, ], @@ -29,6 +32,12 @@ type Bar { foo: Foo } +\\"\\"\\" +The \`BigInt\` scalar type represents non-fractional signed whole numeric values. +@see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt +\\"\\"\\" +scalar BigInt + \\"\\"\\"The \`Byte\` scalar type represents byte value as a Buffer\\"\\"\\" scalar Bytes @@ -38,9 +47,11 @@ A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the \`da scalar DateTime type Foo { + BigIntManually: BigInt BytesManually: Bytes DateTimeManually: DateTime JsonManually: Json + someBigIntField: BigInt! someBytesField: Bytes! someDateTimeField: DateTime! someEnumA: SomeEnumA @@ -74,6 +85,11 @@ import type * as PrismaClient from \\".prisma/client\\" import type { core } from \\"nexus\\" declare global { interface NexusGenCustomInputMethods { + /** + * The \`BigInt\` scalar type represents non-fractional signed whole numeric values. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt + */ + bigInt(fieldName: FieldName, opts?: core.CommonInputFieldConfig): void // \\"BigInt\\"; /** * The \`Byte\` scalar type represents byte value as a Buffer */ @@ -90,6 +106,11 @@ declare global { } declare global { interface NexusGenCustomOutputMethods { + /** + * The \`BigInt\` scalar type represents non-fractional signed whole numeric values. + * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt + */ + bigInt(fieldName: FieldName, ...opts: core.ScalarOutSpread): void // \\"BigInt\\"; /** * The \`Byte\` scalar type represents byte value as a Buffer */ @@ -123,6 +144,7 @@ export interface NexusGenScalars { Float: number Boolean: boolean ID: string + BigInt: any Bytes: any DateTime: any Json: any @@ -149,9 +171,11 @@ export interface NexusGenFieldTypes { foo: NexusGenRootTypes['Foo'] | null; // Foo } Foo: { // field return type + BigIntManually: NexusGenScalars['BigInt'] | null; // BigInt BytesManually: NexusGenScalars['Bytes'] | null; // Bytes DateTimeManually: NexusGenScalars['DateTime'] | null; // DateTime JsonManually: NexusGenScalars['Json'] | null; // Json + someBigIntField: NexusGenScalars['BigInt']; // BigInt! someBytesField: NexusGenScalars['Bytes']; // Bytes! someDateTimeField: NexusGenScalars['DateTime']; // DateTime! someEnumA: NexusGenEnums['SomeEnumA'] | null; // SomeEnumA @@ -167,9 +191,11 @@ export interface NexusGenFieldTypeNames { foo: 'Foo' } Foo: { // field return type name + BigIntManually: 'BigInt' BytesManually: 'Bytes' DateTimeManually: 'DateTime' JsonManually: 'Json' + someBigIntField: 'BigInt' someBytesField: 'Bytes' someDateTimeField: 'DateTime' someEnumA: 'SomeEnumA' diff --git a/tests/e2e/e2e.test.ts b/tests/e2e/e2e.test.ts index 758abe303..8e62faac0 100644 --- a/tests/e2e/e2e.test.ts +++ b/tests/e2e/e2e.test.ts @@ -7,6 +7,7 @@ import { inspect } from 'util' import { assertBuildPresent } from '../__helpers__/helpers' import { createPrismaSchema } from '../__helpers__/testers' import { setupTestProject, TestProject } from '../__helpers__/testProject' +import * as GQLScalars from 'graphql-scalars' const d = debug('e2e') @@ -120,6 +121,7 @@ it('When bundled custom scalars are used the project type checks and generates e someJsonField Json someDateTimeField DateTime someBytesField Bytes + someBigIntField BigInt someEnumA SomeEnumA bar Bar? } @@ -154,7 +156,8 @@ it('When bundled custom scalars are used the project type checks and generates e id: 'foo1', someDateTimeField: new Date("2021-05-10T20:42:46.609Z"), someBytesField: Buffer.from([]), - someJsonField: JSON.stringify({}), + someJsonField: {}, + someBigIntField: BigInt(9007199254740991), someEnumA: 'alpha', bar: { create: { @@ -211,6 +214,8 @@ it('When bundled custom scalars are used the project type checks and generates e t.json('JsonManually') t.dateTime('DateTimeManually') t.bytes('BytesManually') + t.bigInt('BigIntManually') + t.field(Foo.someBigIntField) t.field(Foo.someJsonField) t.field(Foo.someDateTimeField) t.field(Foo.someBytesField) @@ -321,6 +326,9 @@ it('When bundled custom scalars are used the project type checks and generates e expect(stripAnsi(results.runFirstBuild.stdout)).toMatch( /.*error TS2339: Property 'dateTime' does not exist on type 'ObjectDefinitionBlock'.*/ ) + expect(stripAnsi(results.runFirstBuild.stdout)).toMatch( + /.*error TS2339: Property 'bigInt' does not exist on type 'ObjectDefinitionBlock'.*/ + ) expect(results.runReflectPrisma.exitCode).toBe(0) @@ -372,9 +380,12 @@ it('When bundled custom scalars are used the project type checks and generates e JsonManually DateTimeManually BytesManually + BigIntManually someEnumA + someJsonField someDateTimeField someBytesField + someBigIntField } } } @@ -390,4 +401,16 @@ it('When bundled custom scalars are used the project type checks and generates e d(`stopped server`) expect(data).toMatchSnapshot('client request 1') + + const [{ foo }] = data.bars + + expect(foo.JsonManually).toBeNull() + expect(foo.DateTimeManually).toBeNull() + expect(foo.BytesManually).toBeNull() + expect(foo.BigIntManually).toBeNull() + expect(typeof foo.someEnumA).toEqual('string') + expect(typeof foo.someJsonField).toEqual('object') + expect(typeof foo.someDateTimeField).toEqual('string') + expect(typeof foo.someBytesField).toEqual('object') + expect(typeof GQLScalars.BigIntResolver.parseValue(foo.someBigIntField)).toEqual('bigint') }, 60_000) diff --git a/tests/integration/json.test.ts b/tests/integration/json.test.ts index 54e56abe6..44bda6ff0 100644 --- a/tests/integration/json.test.ts +++ b/tests/integration/json.test.ts @@ -16,6 +16,7 @@ testIntegration({ apiSchema({ Foo }) { return [ NexusPrismaScalars.Bytes, + NexusPrismaScalars.BigInt, NexusPrismaScalars.DateTime, NexusPrismaScalars.Json, objectType({ diff --git a/tests/unit/customScalarsModule.test.ts b/tests/unit/customScalarsModule.test.ts index f3b5fd0ab..9fb361da6 100644 --- a/tests/unit/customScalarsModule.test.ts +++ b/tests/unit/customScalarsModule.test.ts @@ -5,18 +5,20 @@ assertBuildPresent() it('scalars can be accessed via namespace import', () => { expect(Object.keys(NexusPrismaScalarsNS)).toMatchInlineSnapshot(` - Array [ - "Bytes", - "DateTime", - "Json", - "default", - ] - `) +Array [ + "BigInt", + "Bytes", + "DateTime", + "Json", + "default", +] +`) }) it('scalars can be accessed via a default import', () => { expect(Object.keys(NexusPrismaScalars)).toMatchInlineSnapshot(` Array [ + "BigInt", "Bytes", "DateTime", "Json", diff --git a/tests/unit/graphqlSchema/__snapshots__/json.test.ts.snap b/tests/unit/graphqlSchema/__snapshots__/json.test.ts.snap index 6be95e870..d7c4841fa 100644 --- a/tests/unit/graphqlSchema/__snapshots__/json.test.ts.snap +++ b/tests/unit/graphqlSchema/__snapshots__/json.test.ts.snap @@ -2,6 +2,12 @@ exports[`When a JSON field is defined in the Prisma schema it can be projected into the GraphQL API: graphqlSchema 1`] = ` " +\\"\\"\\" +The \`BigInt\` scalar type represents non-fractional signed whole numeric values. +@see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt +\\"\\"\\" +scalar BigInt + \\"\\"\\"The \`Byte\` scalar type represents byte value as a Buffer\\"\\"\\" scalar Bytes diff --git a/tests/unit/graphqlSchema/json.test.ts b/tests/unit/graphqlSchema/json.test.ts index 6c4f82c78..5fe34faa5 100644 --- a/tests/unit/graphqlSchema/json.test.ts +++ b/tests/unit/graphqlSchema/json.test.ts @@ -13,6 +13,7 @@ testGraphqlSchema({ `, apiSchema({ Foo }) { return [ + NexusPrismaScalars.BigInt, NexusPrismaScalars.Bytes, NexusPrismaScalars.DateTime, NexusPrismaScalars.Json, diff --git a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap index f527b16f4..e8ac65153 100644 --- a/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap +++ b/tests/unit/typescriptDeclarationFile/__snapshots__/modelScalarFields.test.ts.snap @@ -1,5 +1,271 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`A model field with type BigInt maps to GraphQL BigInt custom scalar: index.d.ts 1`] = ` +"import * as Nexus from 'nexus' +import * as NexusCore from 'nexus/dist/core' + +// +// +// TYPES +// TYPES +// TYPES +// TYPES +// +// + +declare namespace $Types { + // Models + + /** + * Generated Nexus \`objectType\` configuration based on your Prisma schema's model \`SomeModel\`. + * + * ### ️⚠️ You have not writen documentation for model SomeModel + * + * Replace this default advisory JSDoc with your own documentation about model SomeModel + * by documenting it in your Prisma schema. For example: + * + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * foo String + * } + * \`\`\` + * + * Learn more about documentation comments in Prisma schema files [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * @example + * + * import { objectType } from 'nexus' + * import { SomeModel } from 'nexus-prisma' + * + * objectType({ + * name: SomeModel.$name + * description: SomeModel.$description + * definition(t) { + * t.field(SomeModel.id) + * } + * }) + */ + interface SomeModel { + $name: 'SomeModel' + $description: undefined + /** + * Generated Nexus \`t.field\` configuration based on your Prisma schema's model-field \`SomeModel.id\`. + * + * ### ️⚠️ You have not writen documentation for model SomeModel + * + * Replace this default advisory JSDoc with your own documentation about model SomeModel + * by documenting it in your Prisma schema. For example: + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * id String + * } + * \`\`\` + * + * Learn more about documentation comments in Prisma schema files [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * @example + * + * import { objectType } from 'nexus' + * import { SomeModel } from 'nexus-prisma' + * + * objectType({ + * name: SomeModel.$name + * description: SomeModel.$description + * definition(t) { + * t.field(SomeModel.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 + + /** + * The resolver of this field + */ + resolve: NexusCore.FieldResolver<'SomeModel', 'id'> + } + /** + * Generated Nexus \`t.field\` configuration based on your Prisma schema's model-field \`SomeModel.foo\`. + * + * ### ️⚠️ You have not writen documentation for model SomeModel + * + * Replace this default advisory JSDoc with your own documentation about model SomeModel + * by documenting it in your Prisma schema. For example: + * + * \`\`\`prisma + * model SomeModel { + * /// Lorem ipsum dolor sit amet. + * foo BigInt + * } + * \`\`\` + * + * Learn more about documentation comments in Prisma schema files [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * @example + * + * import { objectType } from 'nexus' + * import { SomeModel } from 'nexus-prisma' + * + * objectType({ + * name: SomeModel.$name + * description: SomeModel.$description + * definition(t) { + * t.field(SomeModel.foo) + * } + * }) + */ + foo: { + /** + * The name of this field. + */ + name: 'foo' + + /** + * The type of this field. + */ + type: NexusCore.NexusNonNullDef<'BigInt'> + + /** + * The documentation of this field. + */ + description: undefined + + /** + * The resolver of this field + */ + resolve: NexusCore.FieldResolver<'SomeModel', 'foo'> + } + } + + // Enums + + // N/A –– You have not defined any models in your Prisma schema file. +} + + +// +// +// EXPORTS +// EXPORTS +// EXPORTS +// EXPORTS +// +// + +// +// +// EXPORTS: PRISMA MODELS +// EXPORTS: PRISMA MODELS +// EXPORTS: PRISMA MODELS +// EXPORTS: PRISMA MODELS +// +// + +/** + * Generated Nexus \`objectType\` configuration based on your Prisma schema's model \`SomeModel\`. + * + * ### ️⚠️ You have not writen documentation for model SomeModel + * + * Replace this default advisory JSDoc with your own documentation about model SomeModel + * by documenting it in your Prisma schema. For example: + * + * + * \`\`\`prisma + * /// Lorem ipsum dolor sit amet... + * model SomeModel { + * foo String + * } + * \`\`\` + * + * Learn more about documentation comments in Prisma schema files [here](https://www.prisma.io/docs/concepts/components/prisma-schema#comments). + * + * @example + * + * import { objectType } from 'nexus' + * import { SomeModel } from 'nexus-prisma' + * + * objectType({ + * name: SomeModel.$name + * description: SomeModel.$description + * definition(t) { + * t.field(SomeModel.id) + * } + * }) + */ +export const SomeModel: $Types.SomeModel + +// +// +// EXPORTS: PRISMA ENUMS +// EXPORTS: PRISMA ENUMS +// EXPORTS: PRISMA ENUMS +// EXPORTS: PRISMA ENUMS +// +// + +// N/A –– You have not defined any models in your Prisma schema file. + +// +// +// EXPORTS: OTHER +// EXPORTS: OTHER +// EXPORTS: OTHER +// EXPORTS: OTHER +// +// + +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 +" +`; + exports[`A model field with type Boolean maps to GraphQL Boolean scalar: index.d.ts 1`] = ` "import * as Nexus from 'nexus' import * as NexusCore from 'nexus/dist/core' diff --git a/tests/unit/typescriptDeclarationFile/modelScalarFields.test.ts b/tests/unit/typescriptDeclarationFile/modelScalarFields.test.ts index 77591632a..67c7c02df 100644 --- a/tests/unit/typescriptDeclarationFile/modelScalarFields.test.ts +++ b/tests/unit/typescriptDeclarationFile/modelScalarFields.test.ts @@ -68,6 +68,16 @@ testGeneratedModules({ `, }) +testGeneratedModules({ + description: 'A model field with type BigInt maps to GraphQL BigInt custom scalar', + databaseSchema: ` + model SomeModel { + id String @id + foo BigInt + } + `, +}) + testGeneratedModules({ description: 'A model field with type Bytes maps to GraphQL Bytes custom scalar', databaseSchema: `