Skip to content

[Feature request] Support for non-input types + variables #403

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
robertherber opened this issue Jun 25, 2023 · 10 comments
Closed

[Feature request] Support for non-input types + variables #403

robertherber opened this issue Jun 25, 2023 · 10 comments

Comments

@robertherber
Copy link

Thanks @Code-Hex for creating this plugin! :)

We're doing end-to-end typesafety all the way from MongoDB to the client with our GraphQL schema as a base. Currently we're doing it TypeScript-only, but looking to improve on the DX as well as strictness by using zod both for client-side validation as well as using it to enforce MongoDB Schema Validation.

For this to work well we need to generate zod definitions for:

  • Non-input types as well - we need to cover all GraphQL types as a base for MongoDB Schema Validation (will probably use this or something similar)
  • I noticed zod definitions are not generated for variables directly specified in mutations. I think it'd help a lot to get these as well - I think it makes most sense to break out input types only when they reach a certain level of complexity.

Maybe this is already possible in some way and I've missed how to configure it - but I feel both things would be very helpful to utilize this plugin to it's full potential! :)

@robertherber robertherber changed the title Support for non-input types + variables [Feature request] Support for non-input types + variables Jun 25, 2023
@Code-Hex
Copy link
Owner

@robertherber Thanks!
Non-input types are available with withObject. Please read README more details.

However, I don't support variable for now. Need implementation.

@Code-Hex
Copy link
Owner

Code-Hex commented Jun 25, 2023

Could you tell me example use-case and the code?

I want to reference as real world examples for implementation. (Specifically, I want to know Why you can't use InputObject)

@robertherber
Copy link
Author

robertherber commented Jun 26, 2023

When using withObjectType I end up with this cryptic error message:
Screenshot 2023-06-26 at 08 14 41

And my Codegen looks like this:

overwrite: true
schema: ***
generates:
  src/__generated__/schema.ts:
    plugins:
      - typescript
      - typescript-validation-schema
    config:
      useTypeImports: true
      schema: zod
      nonOptionalTypename: true
      immutableTypes: true
      withObjectType: true # <- without this it works and I get the input types
      directives:
        minLength: min
        # Replace $1 with specified `startsWith` argument value of the constraint directive
        startsWith: [ matches, /^$1/ ]
        format:
          email: email
      scalars:
        DateTime: string
        ObjectId: string
      namingConvention:
        enumValues: keep

As for inputs I would like to be able to use mutations like this:

mutation Login(email: String!, password: String!): String!

// the option now - as far as I understand it is making it extra verbose like this:
input LoginInput {
  email: String!, 
  password: String!
}

mutation Login(loginArgs: LoginInput!): String!

@Code-Hex
Copy link
Owner

@robertherber I'm sorry for being late.
Just stating the facts:

@robertherber
Copy link
Author

Sorry for making it confusing by not providing a syntactically correct schema, I've fixed the example now.

The point is still that I'd like to be able to use arguments directly sent to a mutation and not rely on creating intermediate Input types when it's not necessary.

@Code-Hex
Copy link
Owner

Code-Hex commented Aug 12, 2023

@robertherber I'm not sure what are you expected typescript code generation if I can implement to generate via variables. Could you give me the example?

As I mentioned earlier, variables are document syntax, not schema.
https://spec.graphql.org/June2018/#sec-Language.Variables

@robertherber
Copy link
Author

robertherber commented Aug 12, 2023

I’m not talking about documents but the schema which I hope is clear after I updated the example 🙂

@Code-Hex
Copy link
Owner

Code-Hex commented Aug 13, 2023

@robertherber I meant What do you want Zod schema for variables If you defined this document?

mutation Login(email: String!, password: String!): String!

@Code-Hex
Copy link
Owner

@robertherber I created PR for variables but only for schema.
#453

@Code-Hex
Copy link
Owner

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

2 participants