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

GraphQLDefinitionsFactory should additionally generate wrapped input types #3006

Closed
1 task done
kal4l opened this issue Sep 12, 2023 · 2 comments
Closed
1 task done
Labels

Comments

@kal4l
Copy link

kal4l commented Sep 12, 2023

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Given a schema that uses input objects for queries/mutations:

input SampleEntityInput {
  entityId: String!
}

type Query {
  sampleEntity(input: SampleEntityInput!): SampleEntityResponse!
}

The following types are generated:

export interface SampleEntityInput {
    entityId: string;
}

export interface IQuery {
    sampleEntity(input: SampleEntityInput): SampleEntityResponse | Promise<SampleEntityResponse>;
}

But the actual input that comes in through the resolver is wrapped in input, e.g.

{"input":{"entityId":"fe3ccdf4-6d48-43a6-915a-78843fd64674"}}

Which forces you to define the actual input type yourself in the resolver:

  @Query()
  async sampleEntity(@Args() { input }: { input: SampleEntityInput }) {
    ...
  }

Describe the solution you'd like

Similar to graphql-codegen, additional types should be generated that are wrapped in the input name so they can be used in the resolvers.

e.g.

export interface QuerySampleEntityInput {
    input: SampleEntityInput;
}

And used in the resolver:

  @Query()
  async sampleEntity(@Args() { input }: QuerySampleEntityInput) {
    ...
  }

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

  • Improves the usability of generated types when using objects for query and mutation input.
@kal4l kal4l added the feature label Sep 12, 2023
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this?

@jan-hecker
Copy link

@kal4l you can also pass the name argument to the @ Args() decorator.

  @Query()
  async sampleEntity(@Args('input') input: QuerySampleEntityInput) {
    ...
  }

This then the input object is not wrapped in a object.

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

No branches or pull requests

3 participants