Skip to content

withObjectType option don't support union type #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anhdd-kuro opened this issue Sep 13, 2022 · 2 comments · Fixed by #237
Closed

withObjectType option don't support union type #181

anhdd-kuro opened this issue Sep 13, 2022 · 2 comments · Fixed by #237

Comments

@anhdd-kuro
Copy link
Contributor

anhdd-kuro commented Sep 13, 2022

I have gql file like this

type WorkDivision {
  id: ID!
  name: String!
}

type AttendanceNotEnteredOrDayOff {
  id: ID!
  name: String!
  symbol: String!
}

union AttendanceType = WorkDivision | AttendanceNotEnteredOrDayOff

type Attendance {
  date: String!
  type: AttendanceType!
}

current output

export function AttendanceSchema(): z.ZodObject<Properties<Attendance>> {
  return z.object({
    __typename: z.literal('Attendance').optional(),
    date: z.string().min(1),
    type: definedNonNullAnySchema // wrong !
  })
}

expected output

export function AttendanceTypeSchema(): z.ZodUnion<[z.ZodObject<Required<Properties<WorkDivision>>>, z.ZodObject<Required<Properties<AttendanceNotEnteredOrDayOff>>>]> {
  return z.union([WorkDivisionSchema(), AttendanceNotEnteredOrDayOffSchema()])
}

export function AttendanceSchema(): z.ZodObject<Properties<Attendance>> {
  return z.object({
    __typename: z.literal('Attendance').optional(),
    date: z.string().min(1),
    type: AttendanceTypeSchema()
  })
}
@anhdd-kuro anhdd-kuro reopened this Sep 13, 2022
@anhdd-kuro anhdd-kuro changed the title Don't support union type ? withObjectType object don't support union type Sep 13, 2022
@anhdd-kuro anhdd-kuro changed the title withObjectType object don't support union type withObjectType option don't support union type Sep 13, 2022
@Code-Hex
Copy link
Owner

@anhdd-kuro Thank you for your creating a new issue!
As you know, Basically this plugin is used for input schema mainly. So I don't have the motivation to add some types related to object schema. (like union, fragments, etc...)

It's OK to add some fixes on my side but It's a low priority. However, I appreciate it if you send the PR!

@Code-Hex
Copy link
Owner

@anhdd-kuro published as v0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants