Hi What is the best way to create pisma crud query...
# graphql-nexus
p
Hi What is the best way to create pisma crud query with optional args? I have something like this
Copy code
extendType({
  type: 'Query',
  definition(t) {
    t.list.field('bts', {
      type: 'Bts',
      args: {
        minLat: floatArg({
          default: 0,
          required: true,
        }),
        maxLat: floatArg({
          default: 0,
          required: true,
        }),
        minLong: floatArg({
          default: 0,
          required: true,
        }),
        maxLong: floatArg({
          default: 0,
          required: true,
        }),
      },
      resolve(_root, { minLat, maxLat, minLong, maxLong }, ctx) {
        return ctx.prisma.bts.findMany({
          where: {
            latitude: {
              gte: minLat,
              lte: maxLat,
            },
            longitude: {
              gte: minLong,
              lte: maxLong,
            },
          },
        })
      },
    })
But when I delete required I get error
Copy code
Type 'number | null | undefined' is not assignable to type 'number | undefined'.
  Type 'null' is not assignable to type 'number | undefined'
So what is the best way to handle that optional args?
a
have you tried not setting
required:true
since you have
default
specified
p
then I have this error with null
l
you have to manually convert nulls to undefined
p
thanks for information
Copy code
gte: minLat ?? undefined
works ;)
I have another thing. How put enum in args?
I have enumType
Copy code
export const ProviderEnum = enumType({
  name: 'ProviderEnum',
  members: {
    PLUS: 'Plus',
    PLAY: 'Play',
    ORANGE: 'Orange',
  },
})
and in argument a want to pass list of elements from this enum and I don’t have idea :/
r
If you want a list, then you could do it like this:
Copy code
args: {
  type: arg({ type: 'ProviderEnum', list: true }),
},
Where
arg
comes from
@nexus/schema
p
ok it’s working but is possible to make a hint on playground to put this Enum or put in to docs? And what is the best way to create validation of this args enum?
r
Are you talking about these? I’m getting it in the docs and the type hints
p
@Ryan thanks is working 😉 I don’t rebuild my schema
💯 1