Esri / arcgis-rest-js

compact, modular JavaScript wrappers for the ArcGIS REST API
https://developers.arcgis.com/arcgis-rest-js/
Apache License 2.0
353 stars 119 forks source link

custom params get dropped in generic search #657

Open asizer opened 4 years ago

asizer commented 4 years ago

I was trying to do a searchItems with custom params, but they kept getting stripped out.

It looks like genericSearch (which is used by searchItems) only allows these params: https://github.com/Esri/arcgis-rest-js/blob/13bbea4ee995c1a7ba6936ea4ad16c3ff887927f/packages/arcgis-rest-portal/src/util/generic-search.ts#L29-L35

even though ISearchOptions type definition looks like it's possible to add other params: https://github.com/Esri/arcgis-rest-js/blob/13bbea4ee995c1a7ba6936ea4ad16c3ff887927f/packages/arcgis-rest-portal/src/util/search.ts#L8-L13

should item search support all these parameters? https://developers.arcgis.com/rest/users-groups-and-items/search.htm#GUID-A2C8BFD1-89B2-483F-9275-65D2786F6A6C

asizer commented 4 years ago

ugh, sorry, wrong repo 🤦‍♀

jgravois commented 4 years ago

hi @asizer! :wave:

I know you said you logged this in the wrong repo, but just a heads up, you can use ISearchOptions.params to pass through any request parameter you want.


searchItems({
  params: { foo: 'bar' }
})
asizer commented 4 years ago

ooh, thanks so much @jgravois, that works! sorry i missed that!

asizer commented 4 years ago

ok, sorry, it's late, and tired, so i may be mistaken, but it's looking to me like params gets reassigned with all the standard stuff in my query as part of appendCustomParams. So if I start out with:

search: {
  q: "my awesome query here",
  start: 1,
  num: 100,
  params: {
    categories: "/Categories/Trending"
  }
}

it becomes this after appendCustomParams:

search: {
  q: "my awesome query here",
  start: 1,
  num: 100,
  params: {
    categories: "/Categories/Trending"
    q: "my awesome query here",
    start: 1,
    num: 100,
    params: {  // <--- OH NO!
      categories: "/Categories/Trending" 
      ... 
      (repeat all the search properties circularly and infinitely here)
      ...
    }
  }
}

here's appendCustomParams. should the starting value maybe be {} instead of options.params?: https://github.com/Esri/arcgis-rest-js/blob/13bbea4ee995c1a7ba6936ea4ad16c3ff887927f/packages/arcgis-rest-request/src/utils/append-custom-params.ts#L31-L37

or maybe it's how this is interacting with the genericSearch and the search properties enumerated there? https://github.com/Esri/arcgis-rest-js/blob/b91af15a0524ace69edfdaa5ccdea9da257746a9/packages/arcgis-rest-portal/src/util/generic-search.ts#L29-L35

jgravois commented 4 years ago

it becomes this after appendCustomParams

search: {
q: "my awesome query here",
start: 1,
num: 100,
params: {
categories: "/Categories/Trending"
q: "my awesome query here",
start: 1,
num: 100,
params: {  // <--- OH NO!
categories: "/Categories/Trending" 
... 
(repeat all the search properties circularly and infinitely here)
...
}
}
}

are you saying those are the request parameters? this test would lead me to believe that the library is already doing what its supposed to.

https://github.com/Esri/arcgis-rest-js/blob/25778e3e6b16d73cc22a79a7b9bc1c97f4f90ac4/packages/arcgis-rest-portal/test/items/search.test.ts#L139-L164