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

Wrong value for context.method in create hook #3428

Closed
lukvermeulen opened this issue Feb 12, 2024 · 3 comments
Closed

Wrong value for context.method in create hook #3428

lukvermeulen opened this issue Feb 12, 2024 · 3 comments

Comments

@lukvermeulen
Copy link

Context

I noticed the query resolver running on create methods - causing my app to prevent the creation of an item since I was limiting the query by a property that does not exist for the user without creating sad item (a user needs to create a tenant, that is then assigned to him. He can only view tenant information of his own tenant - thats what the query resolver is for.)

To keep my getTenantId resolver generic, I added a configuration option to skip the check on certain methods (e.g. create), while keeping the query resolver itself intact on all methods.

Error

Thats when I noticed, that context.method returned findin all cases - even on create calls.

Steps to reproduce

I discovered logging context.method always prints "find", even in hooks.

Adding this example hook

async (context) => {
  console.log(context.method);
},

to the before > create hook also returns findwhen creating an object.

before: {
  all: [schemaHooks.validateQuery(channelQueryValidator), schemaHooks.resolveQuery(channelQueryResolver)],
  find: [],
  get: [],
  create: [
    async (context) => {
      console.log(context.method);
    },
    schemaHooks.validateData(channelDataValidator),
    schemaHooks.resolveData(channelDataResolver),
  ],
  patch: [schemaHooks.validateData(channelPatchValidator), schemaHooks.resolveData(channelPatchResolver)],
  remove: [],
},

Expected behavior

I'm not sure what is causing this, as this happens on all services for me. I expect the method to return the name of the method, e.g. create, get, ...

Actual behavior

context.methodholds the value findin all cases, ignore the actual method type that was called.

System configuration

Tell us about the applicable parts of your setup.

Module versions: @featherjs .. tested with 5.0.9, 5.0.21

NodeJS version: 18.17

Operating System: mac os

@lukvermeulen lukvermeulen changed the title Wrong context.method in create hook Wrong value for context.method in create hook Feb 12, 2024
@daffl
Copy link
Member

daffl commented Feb 15, 2024

I am not able to reproduce this and would be surprised if this was a general issue since many applications and plugins are using similar checks. Please provide a full repository that illustrates your problem.

@lukvermeulen
Copy link
Author

lukvermeulen commented Feb 16, 2024

Thanks alot for the heads up. I dug into it again and it looks like some noise made me miss a stupid typo.
Sorry for the noise!

@daffl
Copy link
Member

daffl commented Feb 16, 2024

That's ok, if it was something that was easy to break it would've still made sense to look into.

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