Skip to content
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

Generate schemas for Query operations #472

Open
macmillen opened this issue Sep 1, 2023 · 0 comments
Open

Generate schemas for Query operations #472

macmillen opened this issue Sep 1, 2023 · 0 comments

Comments

@macmillen
Copy link

I need the schemas not just for graphql inputs but also for graphql queries to be able to validate preloaded data from the database for a page. I can't just use withObjectType because it potentially contains more fields than the graphql query.

Example

GraphQL type:

type Author {
  email: String!
  name: String!
  password: String!
}

My GraphQL query operation:

query Author {
  author {
    email
  }
}

The zod schema I get:

export function AuthorSchema(): z.ZodObject<Properties<Author>> {
  return z.object({
    email: z.string(),
    name: z.string(), // this field I don't want
    password: z.string() // this field I don't want
  })
}

Instead I need a schema like this:

export function AuthorQuerySchema(): z.ZodObject<Properties<AuthorQuery>> {
  return z.object({
    email: z.string()
  })
}
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

No branches or pull requests

1 participant