Nexus: how to support something like a date / dateTime arg?

Created on 23 Apr 2019  路  3Comments  路  Source: graphql-nexus/nexus

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.

question

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasonkuhrt picture jasonkuhrt  路  5Comments

ecwyne picture ecwyne  路  6Comments

capaj picture capaj  路  5Comments

delianides picture delianides  路  6Comments

deadcoder0904 picture deadcoder0904  路  3Comments