Skip to content

Generate schemas for Query operations #472

Open
@macmillen

Description

@macmillen

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()
  })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions