I'm moving over to nexus and so far I'm pretty happy with it. However I've run into something I'm confused about around args that are not provided by nexus. For example I have the following:
t.field('setDeleted', {
type: 'Task',
args: {
id: idArg({ required: true }),
deletedAt: stringArg({ required: true }),
},
resolve: (_parent, { id, deletedAt }, ctx) => {
return ctx.prisma.updateTask({
where: { id },
data: { isDeleted: true, deletedAt: deletedAt },
})
},
})
However with this I get an error: Variable "$deletedAt" of type "DateTime!" used in position expecting type "String!".
so I'm curious how to support an arg type that isn't provided by nexus.
You can use the arg and create little helpers for these as you see fit (assumes DateTime is available as a custom scalar):
const dateTimeArg = (opts) => arg({ ...opts, type: "DateTime" })
ok, thanks, any help on what the type for opts would be?
I'm using:
const dateTimeArg = (opts: core.CommonArgConfig) =>
arg({ ...opts, type: 'DateTime' })
which seems to work, but really is just a guess :D
Yep, that or this should work:
import { arg, core } from 'nexus'
const dateTimeArg = (
opts: core.NexusArgConfig<'DateTime'>
) => arg({ ...opts, type: "DateTime" })
Really the only difference is the type for the default value.
Most helpful comment
Yep, that or this should work:
Really the only difference is the type for the
defaultvalue.