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

fastJoin Error #645

Open
Ryan8765 opened this issue Nov 3, 2021 · 3 comments
Open

fastJoin Error #645

Ryan8765 opened this issue Nov 3, 2021 · 3 comments

Comments

@Ryan8765
Copy link

Ryan8765 commented Nov 3, 2021

Version: 5.0.6 with feathers version 4.5.11

I'm working with fastJoin and for some reason unable to get it to work. Code:

const postResolvers = {
  joins: {
    conf: (...args) => async (connection, context) => {
      try {
        var conf = await context.app.service('con-configs').find({
          query: {
            type: connection.type
          }
        });
      } catch (error) {
        return Promise.reject(new GeneralError(`Error`));
      }
      connection.conf= conf.data[0];
    }
  }
};

I'm using this in a before hook:

before: {
   
    find: [
      fastJoin(postResolvers)
    ]
  }

Error message:

"TypeError: Cannot read property 'data' of undefined\n at /app/node_modules/feathers-hooks-common/lib/services/fast-join.js:13:48\n at /app/node_modules/feathers-hooks-common/node_modules/@feathersjs/commons/lib/hooks.js:116:46\n at processTicksAndRejections (node:internal/process/task_queues:94:5)"

@skinofstars
Copy link

Not sure if you resolved this, but you probably want to change your hook from a before to an after.

@strarsis
Copy link

strarsis commented Apr 2, 2022

+1, I have the same issue:

@feathersjs/express/rest Error in handler: `Cannot read properties of undefined (reading 'data')` +5ms
[...]
@feathersjs/errors GeneralError(500): Cannot read properties of undefined (reading 'data') +0ms

I can use the hook in after instead of before – but I thought the fastJoin hook also handles upserts (what depopulate would handle). This isn't the case when the hook is only used in after where results can be modified, but not what is processed in upserts.

@skinofstars
Copy link

skinofstars commented Apr 5, 2022

As far as I'm aware (very happy if someone can show me I'm wrong), fastJoin only works in after hooks. It takes the data the service has loaded and uses that data to find the related items.

I personally hit issues with this when I'm looking to filter on joined data. In these cases I modify the knex query (I'm almost all in PostgresSQL) in a before hook. Other possible solutions might be: custom service where you do all querying/updating in service calls; using view tables; pre-loading data in before hooks.

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

3 participants