data icon indicating copy to clipboard operation
data copied to clipboard

[5.3.9] Builded url for `this.store.query` incorrect when passing `include` as array

Open mkszepp opened this issue 1 year ago • 2 comments

The this.store.query (legacy adapters) isn't working correctly when we pass includes as array.

this.store.query<Company>('company', {
  filter: {
    type: 'example',
  },
  include: ['ceo', 'employee'],
});

The query params result in url is: &include[]=ceo&include[]=employee

it should be &include=ceo,employee

This bug was fixed for findAll & findRecord in #9583

It was not fixed for query (maybe also other) because this.buildQuery will not be called inside that function

https://github.com/emberjs/data/blob/83c176c2b561bea98616015fb9b643ccf0f5e4da/packages/adapter/src/rest.ts#L587-L595

mkszepp avatar Nov 06 '24 11:11 mkszepp

I have the same issue, where I need the query url formatted like &include=ceo,employee

Giving it as string for now so that it continues to work against the API as it is written, but then I need to ignore type issues.

Techn1x avatar Feb 27 '25 08:02 Techn1x

@Techn1x just as tip... we have also initial hold as string in TS project, but removing all eslint disabled... were again so much work At the end we have created a override in our apps in application adapter

// Fix for reported issue https://github.com/emberjs/data/issues/9588
  override query(store: Store, type: ModelSchema, query: Record<string, unknown>): Promise<AdapterPayload> {
    if (query) {
      const { include } = query;
      const normalizedInclude = Array.isArray(include) ? include.join(',') : include;

      if (normalizedInclude) {
        query['include'] = normalizedInclude;
      }
    }

    return super.query(store, type, query);
  }

mkszepp avatar Feb 27 '25 09:02 mkszepp