diff --git a/src/builder.ts b/src/builder.ts index 0ee370b2..c5cfa5d1 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -557,7 +557,18 @@ export class SchemaBuilder { buildFieldConfig( config: FieldConfigData, ): Nexus.core.NexusOutputFieldConfig { + const { + alias, + locallyComputedInputs, + type, + filtering, + ordering, + pagination, + ...additionalExternalPropsSuchAsPlugins + } = config.publisherConfig + return { + ...additionalExternalPropsSuchAsPlugins, type: this.publisher.outputType( config.publisherConfig.type, config.field, diff --git a/src/typegen.ts b/src/typegen.ts index 88f8ee1b..4ad3b9b9 100644 --- a/src/typegen.ts +++ b/src/typegen.ts @@ -231,9 +231,9 @@ function renderStaticTypes() { ? true : false - type NexusPrismaScalarOpts = { - alias?: string - } + type NexusPrismaScalarOpts = { + alias?: Alias + } & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -332,21 +332,21 @@ function renderStaticTypes() { export type Context = core.GetGen<'context'> - type BaseRelationOptions = + type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. - type NexusPrismaRelationOpts = + type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -431,14 +431,14 @@ function renderStaticTypes() { // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/__app/generated/nexus-prisma-typegen.d.ts b/tests/__app/generated/nexus-prisma-typegen.d.ts index bb7580c7..55e2113c 100644 --- a/tests/__app/generated/nexus-prisma-typegen.d.ts +++ b/tests/__app/generated/nexus-prisma-typegen.d.ts @@ -8,9 +8,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -109,21 +109,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -208,14 +208,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/__client-test-context.ts b/tests/__client-test-context.ts index 71fc95de..1c59e991 100644 --- a/tests/__client-test-context.ts +++ b/tests/__client-test-context.ts @@ -1,3 +1,4 @@ +import * as Nexus from '@nexus/schema' import { MigrateEngine } from '@prisma/migrate' import { getGenerator } from '@prisma/sdk' import * as fs from 'fs' @@ -15,6 +16,7 @@ type RuntimeTestContext = { getContext: (args: { datamodel: string types: any[] + plugins?: Nexus.core.NexusPlugin[] }) => Promise<{ graphqlClient: GraphQLClient dbClient: any @@ -43,7 +45,7 @@ export function createRuntimeTestContext(): RuntimeTestContext { afterEach(teardownCtx) return { - async getContext({ datamodel, types }) { + async getContext({ datamodel, types, plugins }) { try { // Force query engine binary path process.env.PRISMA_QUERY_ENGINE_BINARY = await getEnginePath('query') @@ -54,6 +56,7 @@ export function createRuntimeTestContext(): RuntimeTestContext { const serverAndClient = await getGraphQLServerAndClient( datamodel, types, + plugins ?? [], prismaClient, ) httpServer = serverAndClient.httpServer @@ -75,13 +78,12 @@ export function createRuntimeTestContext(): RuntimeTestContext { async function getGraphQLServerAndClient( datamodel: string, types: any[], + plugins: Nexus.core.NexusPlugin[], prismaClient: { client: any; teardown(): Promise }, ) { - const { schema, schemaString } = await generateSchemaAndTypes( - datamodel, - types, - {}, - ) + const { schema, schemaString } = await generateSchemaAndTypes(datamodel, types, { + plugins, + }) const port = await getPort() const endpoint = '/graphql' const graphqlServer = new GraphQLServer({ diff --git a/tests/__snapshots__/app.test.ts.snap b/tests/__snapshots__/app.test.ts.snap index 7d488c15..c4626c27 100644 --- a/tests/__snapshots__/app.test.ts.snap +++ b/tests/__snapshots__/app.test.ts.snap @@ -565,9 +565,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -666,21 +666,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -765,14 +765,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/__utils.ts b/tests/__utils.ts index fe2eabf2..68edff97 100644 --- a/tests/__utils.ts +++ b/tests/__utils.ts @@ -48,7 +48,10 @@ export async function getPinnedDmmfFromSchema(datamodel: string) { export async function generateSchemaAndTypes( datamodel: string, types: any[], - options?: TransformOptions & { experimentalCRUD?: boolean }, + options?: TransformOptions & { + experimentalCRUD?: boolean + plugins?: Nexus.core.NexusPlugin[] + }, ) { const dmmf = await getDmmf(datamodel, options) const nexusPrisma = createNexusPrismaInternal({ @@ -57,7 +60,7 @@ export async function generateSchemaAndTypes( }) const schema = Nexus.makeSchema({ types, - plugins: [nexusPrisma], + plugins: [nexusPrisma, ...(options?.plugins ?? [])], outputs: false, }) diff --git a/tests/runtime/__snapshots__/plugins.test.ts.snap b/tests/runtime/__snapshots__/plugins.test.ts.snap new file mode 100644 index 00000000..3621e0db --- /dev/null +++ b/tests/runtime/__snapshots__/plugins.test.ts.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`forwards plugins to t.crud 1`] = `[Error: Not authorized: {"response":{"data":null,"errors":[{"message":"Not authorized","locations":[{"line":2,"column":7}],"path":["users"]}],"status":200},"request":{"query":"{\\n users {\\n id\\n }\\n }"}}]`; + +exports[`forwards plugins to t.model 1`] = `[Error: Not authorized: {"response":{"data":null,"errors":[{"message":"Not authorized","locations":[{"line":3,"column":9}],"path":["users",0,"id"]}],"status":200},"request":{"query":"{\\n users {\\n id\\n }\\n }"}}]`; diff --git a/tests/runtime/plugins.test.ts b/tests/runtime/plugins.test.ts new file mode 100644 index 00000000..ad2bbfe8 --- /dev/null +++ b/tests/runtime/plugins.test.ts @@ -0,0 +1,100 @@ +import { objectType, fieldAuthorizePlugin } from '@nexus/schema' +import { createRuntimeTestContext } from '../__client-test-context' + +let ctx = createRuntimeTestContext() + +it('forwards plugins to t.model', async () => { + const datamodel = ` + model User { + id Int @id @default(autoincrement()) + name String + } + ` + const User = objectType({ + name: 'User', + definition(t: any) { + t.model.id({ + authorize() { + return new Error('nope') + }, + }) + }, + }) + + const Query = objectType({ + name: 'Query', + definition(t: any) { + t.crud.users() + }, + }) + + const { graphqlClient, dbClient } = await ctx.getContext({ + datamodel, + types: [Query, User], + plugins: [fieldAuthorizePlugin()], + }) + + await dbClient.user.create({ + data: { + name: 'Foo', + }, + }) + + try { + await graphqlClient.request(`{ + users { + id + } + }`) + } catch (e) { + expect(e).toMatchSnapshot() + } +}) + +it('forwards plugins to t.crud', async () => { + const datamodel = ` + model User { + id Int @id @default(autoincrement()) + name String + } + ` + const User = objectType({ + name: 'User', + definition(t: any) { + t.model.id() + }, + }) + + const Query = objectType({ + name: 'Query', + definition(t: any) { + t.crud.users({ + authorize() { + return new Error('nope') + }, + }) + }, + }) + + const { graphqlClient, dbClient } = await ctx.getContext({ + datamodel, + types: [Query, User], + plugins: [fieldAuthorizePlugin()], + }) + + await dbClient.user.create({ + data: { + name: 'Foo', + }, + }) + + try { + await graphqlClient.request(`{ + users { + id + } + }`) + } catch (e) { + expect(e).toMatchSnapshot() + } +}) diff --git a/tests/schema/__snapshots__/computedInputs.test.ts.snap b/tests/schema/__snapshots__/computedInputs.test.ts.snap index cd8e74d0..aec87076 100644 --- a/tests/schema/__snapshots__/computedInputs.test.ts.snap +++ b/tests/schema/__snapshots__/computedInputs.test.ts.snap @@ -70,9 +70,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -171,21 +171,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -270,14 +270,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] @@ -419,9 +419,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -520,21 +520,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -619,14 +619,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/schema/__snapshots__/enums.test.ts.snap b/tests/schema/__snapshots__/enums.test.ts.snap index f6792daa..ab955eec 100644 --- a/tests/schema/__snapshots__/enums.test.ts.snap +++ b/tests/schema/__snapshots__/enums.test.ts.snap @@ -36,9 +36,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -137,21 +137,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -236,14 +236,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] @@ -373,9 +373,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -474,21 +474,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -573,14 +573,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] @@ -687,9 +687,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -788,21 +788,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -887,14 +887,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/schema/__snapshots__/filtering-ordering.test.ts.snap b/tests/schema/__snapshots__/filtering-ordering.test.ts.snap index 07e5e0ee..cfe3b232 100644 --- a/tests/schema/__snapshots__/filtering-ordering.test.ts.snap +++ b/tests/schema/__snapshots__/filtering-ordering.test.ts.snap @@ -35,9 +35,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -136,21 +136,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -235,14 +235,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/schema/__snapshots__/naming.test.ts.snap b/tests/schema/__snapshots__/naming.test.ts.snap index 9c1b7391..42327df4 100644 --- a/tests/schema/__snapshots__/naming.test.ts.snap +++ b/tests/schema/__snapshots__/naming.test.ts.snap @@ -86,9 +86,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -187,21 +187,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -286,14 +286,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName] diff --git a/tests/schema/__snapshots__/outputs.test.ts.snap b/tests/schema/__snapshots__/outputs.test.ts.snap index e88ed8af..28cb239e 100644 --- a/tests/schema/__snapshots__/outputs.test.ts.snap +++ b/tests/schema/__snapshots__/outputs.test.ts.snap @@ -58,9 +58,9 @@ type IsModelNameExistsInGraphQLTypes = ? true : false -type NexusPrismaScalarOpts = { - alias?: string -} +type NexusPrismaScalarOpts = { + alias?: Alias +} & NexusGenPluginFieldConfig type Pagination = { skip?: boolean @@ -159,21 +159,21 @@ export type LocalMutationResolverParams = export type Context = core.GetGen<'context'> -type BaseRelationOptions = +type BaseRelationOptions = DynamicRequiredType & { - alias?: string + alias?: Alias computedInputs?: LocalComputedInputs - } + } & NexusGenPluginFieldConfig // If GetNexusPrismaInput returns never, it means there are no filtering/ordering args for it. -type NexusPrismaRelationOpts = +type NexusPrismaRelationOpts = GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else if : GetNexusPrismaInput extends never - ? BaseRelationOptions + ? BaseRelationOptions // else - : BaseRelationOptions & { + : BaseRelationOptions & { filtering?: | boolean | Partial, boolean>> @@ -258,14 +258,14 @@ type NexusPrismaMethod< // else if // if scalar return scalar opts : ThisKind extends AKind<'Scalar'> - ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields + ? (opts?: NexusPrismaScalarOpts) => NexusPrismaFields // else if // if model name has a mapped graphql types then make opts optional : IsModelNameExistsInGraphQLTypes extends true - ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields + ? (opts?: NexusPrismaRelationOpts) => NexusPrismaFields // else // force use input the related graphql type -> { type: '...' } - : (opts: NexusPrismaRelationOpts) => NexusPrismaFields + : (opts: NexusPrismaRelationOpts) => NexusPrismaFields type GetNexusPrismaMethod = TypeName extends keyof NexusPrismaMethods ? NexusPrismaMethods[TypeName]