incetarik / nestjs-graphql-zod

A library providing dynamic GraphQL object classes from their zod validation objects.
Mozilla Public License 2.0
86 stars 11 forks source link

Nested object not working with zod extend or merge #30

Open noru opened 3 weeks ago

noru commented 3 weeks ago

As title.

Seems it cannot correctly generate the nested model with extend/merge.

import { QueryWithZod, ZodArgs } from 'nestjs-graphql-zod'
import { z } from 'zod'
const Base = z.object({
  foo: z.string(),
  nested: z.object({ bar: z.string() }),
})

const Sub = Base.extend({
  baz: z.string(),
  // nested: z.object({ bar: z.string() }), manually override this property will work
})

export class AppMetaResolver {

  @QueryWithZod(Sub)
  async createApp(@ZodArgs(Base) input: ZodArgs.Of<typeof Base>) {
    // ...
  }
}
CannotDetermineInputTypeError: Cannot determine a GraphQL input type ("DynamicZodModel") for the "nested". Make sure your class is decorated with an appropriate decorator.
    at InputTypeFactory.create 
noru commented 4 days ago

Seems input model cannot be overlap in @QueryWithZod and @ZodArgs...

For anyone that cares, I do a schema deep clone when input/output type get cross referencing.