-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
Custom Param Decorator breaks other @Arg if not last argument #1325
Comments
I'm not sure if it's about
Can you try to reproduce the issue with simple |
@MichalLytek how could I create a param decorator that creates an argument without doing it the way I am? |
Your issue is about arg after custom param decorator. I'm not responsible for supporting your patterns like composing decorators and calling them manually. |
? It's not my pattern - I am trying to use type-graphql the way it's intended. Namely, you support custom parameter decorators and annotation-based graphql Arguments. I want to create a custom decorator (as you support) that creates an |
After digging in some more, I can see how this isn't currently doable with type-graphql's implementation. The argument will always have two params in ParamMetadata - one with type "arg", one with type "custom". "getParams" maps the param metadata into an array of params, so the two params will always be in there, and there is no way to tell type-graphql which to prioritize. I can think of a few ways to change this behavior and am open to submitting a PR but should discuss design first:
Example:
|
@MichalLytek here is my proposed solution |
I am also having the same issue. We are trying to modify the incoming object to add the user created and modified at data to one of the args. |
@DrakeAnglin looking at the history of issues and PR's on this repo, you might be better off forking the repo than waiting for a merge. Feel free to use our fork #1330 |
Describe the Bug
We are using custom param decorators to inject args when derived by user, and allow overriding those args in other circumstances. For example, a normal user can only access their own account, while an admin user can access any account - so we use a nullable accountId argument and our decorator auto-fills it with the user's accountId if that user is a non-admin.
Here is some sample code:
The issue is, that when this custom param is the only argument, it works fine. If it's the last argument, it also works fine. But if it's somewhere in the middle (e.g. @ctx() context, @AccountIdArg accountId, @arg('input') input: SomeInputType), the third argument (input) will be undefined. Here are some screenshots of a debugger in different states:
First Arg
Notice how "input" is undefined
Second Arg
Now "input" is working as expected - the only change is switching the order of the arguments.
To Reproduce
Use the decorator code above and set "currentUser.accountId" to some string in your context, then create a query or mutation with the new param decorator.
Expected Behavior
The param decorator should work regardless of which order the argumetns are in.
Logs
See screenshot, debugger is clearest example
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: