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

@Field() midleware not running on @ArgsType() or @InputType() #2446

Closed
2 of 4 tasks
dragosmc opened this issue Oct 12, 2022 · 4 comments
Closed
2 of 4 tasks

@Field() midleware not running on @ArgsType() or @InputType() #2446

dragosmc opened this issue Oct 12, 2022 · 4 comments

Comments

@dragosmc
Copy link

dragosmc commented Oct 12, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The behaviour described in the documentation under Field middleware indicates that the middlewares are driven by the @Field() decorator, but I found that they don't work for all types.

In other words, the middlewares only get called on ObectType() but not on @ArgsType() or @InputType().

The code snippets are take from the main branch of this repo and the middleware is the one described in the documentation here https://docs.nestjs.com/graphql/field-middleware

Minimum reproduction code

https://gist.github.com/dragosmc/1e59619831f78be9b3420f6e7affd928

Steps to reproduce

No response

Expected behavior

The output to contain the output of all 3 for running the e2e tests that were modified with the middlewares in the gist.

 yarn test:e2e

Package version

10.1.3

Graphql version

No response

NestJS version

10.1.3

Node.js version

16.15.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@dragosmc dragosmc changed the title @Field() miidleware not running on @ArgsType() or @InputType() @Field() midleware not running on @ArgsType() or @InputType() Oct 13, 2022
@kamilmysliwiec
Copy link
Member

This is intentional (GraphQLField supports declaring the resolve method, while GraphQLInputField does not - both classes come from the graphql package). Still, to make this behavior a bit more straightforward, we should probably throw an error (or at least log a warning down to the console) to inform users that middleware functions registered on the input/arg type field level will be ignored.

Would you like to create a PR for this issue?

@equal-matt
Copy link

@kamilmysliwiec - what is the intended solution for running middleware-like transformations on input/arg types? More than happy to do a quick docs PR, but I'm not sure what the message is.

@equal-matt
Copy link

graphql/graphql-js#361 - continuing discussion about field middleware support for when I find this in the future.

@kamilmysliwiec
Copy link
Member

let's track this here graphql/graphql-js#361

@nestjs nestjs locked and limited conversation to collaborators Feb 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants