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

Args decorator try to read property of undefined #724

Closed
techo207 opened this issue Oct 13, 2020 · 2 comments · Fixed by #733
Closed

Args decorator try to read property of undefined #724

techo207 opened this issue Oct 13, 2020 · 2 comments · Fixed by #733
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community Solved ✔️ The issue has been solved
Milestone

Comments

@techo207
Copy link

Describe the Bug
I'm not sure if it is a bug, or my specific use case.
I'm creating a custom decorator that inject a generic find function as field function in the ObjectType class. to achive it i'm using the Args decorator as a function but it throws a error in runtine.

Cannot read property '0' of undefined

To Reproduce

@ArgsType()
class Ca{
   @Field(() => String)
   a: string;
}

@ObjectType()
class A {
    @ConnectionField( () => ProductFindArgs )
    prueba;
}

export function ConnectionField( findArgs: any, options?: FieldOptions ) {
	return function ConnectionDecorator( target: any, propertyKey: string | symbol ) {
		const newPropertyName = `_${String( propertyKey )}Connection`;
		const field = Field( () => String , { name: String( propertyKey ) } );
		const args = Args(findArgs);
		target[newPropertyName] = async function ConnectionFieldResolver( { a }: any ) {
			return findMany( a );
		};
		const descriptor :PropertyDescriptor = { configurable: true, enumerable: true, writable: true };
		args( target, newPropertyName, 0 );
		field( target, newPropertyName, descriptor );
	};
}

Expected Behavior
I expected that it create a function to resolve prueba field inside object type, but it throws a error

I can resolve the problem just adding a optional chaining in line 11 inside /dist/helpers/findType.js , just like

 metadataDesignType = reflectedType?.[parameterIndex];

Logs
at .../node_modules/type-graphql/dist/helpers/findType.js:11
metadataDesignType = reflectedType[parameterIndex];
^
TypeError: Cannot read property '0' of undefined
at .../node_modules/type-graphql/dist/helpers/findType.js:11:43)
at Object.getParamInfo (.../node_modules/type-graphql/dist/helpers/params.js:10:49)
at. .../node_modules/type-graphql/dist/decorators/Args.js:12:25

Environment (please complete the following information):

  • OS: mac os
  • Node 14.0
  • Package version lastest
  • TypeScript version 4.0.3
@techo207
Copy link
Author

techo207 commented Oct 13, 2020

I've create a pull request to resolve it

#use optional chaining to get value inside reflectedType #725

@MichalLytek MichalLytek reopened this Oct 18, 2020
@MichalLytek
Copy link
Owner

Reopening the issue as the proper fix is ready on #733

@MichalLytek MichalLytek added Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community labels Oct 18, 2020
@MichalLytek MichalLytek added this to the 1.x versions milestone Oct 18, 2020
@MichalLytek MichalLytek added the Solved ✔️ The issue has been solved label Oct 20, 2020
@MichalLytek MichalLytek modified the milestones: 1.x versions, 1.2 Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community Solved ✔️ The issue has been solved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants