marshallswain / feathers-pinia

Connect your Feathers API to the elegant data store for Vue
52 stars 22 forks source link

Params not passed to server #150

Open EmileSpecs opened 9 months ago

EmileSpecs commented 9 months ago

Hi

Perhaps I'm missing something, why is the params not passed to the server here?

const { api } = useFeathers()
const service = api.service('users')
const state = service.new()

state.save({
    $clientData: {
      verifyUrl: `${url.protocol}//${url.host}/auth/status/verified`
    }
  })

The query params is received empty on the server. I've added $clientData to paramsForServer list in createPiniaClient config.

Even though params is listed for all instance methods, in the Pinia client config is says: "paramsForServer is an array of query keys for findInStore to ignore and pass to the find action's query."

So does params only get sent to server for find?

If so, is there no other way to send params for other types of requests?

EmileSpecs commented 9 months ago

I've tested this quite thoroughly now and it seems like for instance.create no params are passed to server, it's also not present in feathersClient before hooks.

For instance.patch however, the params are set in before hooks.

The paramsForServer still doesn't seem to do anything though?

My expectation is that it is added to params.query.$client (for example) and then I use the paramsFromClient hook on the server to add it back into ctx.params and remove it from the query.

I've now done that manually in all before hooks:

before: {
      all: [
        (ctx: any) => {
          const { query, ...params } = ctx.params

            // add the $client key to the query
            if (Object.keys(params).length > 0) {
              ctx.params.query = {
                $client: params,
                ...query,
              }
            }
}
]}

So this workaround works well for anything besides instance.create as no params are passed to the Feathers client. Is this expected behaviour, as the docs specify that a params param is accepted for instance.create.

marshallswain commented 8 months ago

Every Feathers interface accepts params, but params aren't passed by default. I'm not sure that I've ever used custom params on create. It makes more sense to me to use the data interface for create, now... but it seems like I did have params working for create back in the feathers-vuex days. I'm not sure when I'll be able to address this. I'm merging in all PRs that are ready, today. If you want to create a PR, I'll review it in the next batch, which would be a couple of weeks away, likely. If not, please work around the issue by using data.