Properly change the format of queries

5981
5
Jump to solution
06-17-2020 11:10 PM
ShanonLoughton
Esri Contributor

Hi

For a particular situation, in ArcGIS for JS API 4.15 I am trying to force a particular format of all Feature Server (FS) queries to JSON (f=json, or f=pjson), regardless of the ArcGIS Server's (10.7.1) > Feature Service's > Layer config params, such as  SupportedQueryFormats: JSON, GeoJSON, PBF. It looks like PBF is preferred to be used by clients, if it is available.

I have forced f=json with esri.Config.request successfully:

require([
 "esri/config",
 ...
 ], function(esriConfig,...) {
    esriConfig.request.interceptors.push({ 
       before(params) {
          if (params.url.includes("query")) {
             params.requestOptions.query.f = 'json';
          }
       }
    }
   ...
 });

which works at the call level. However when the query is originally PBF, the client JS SDK is expecting it to come back and be parsed as PBF still, even though I have intercepted the initial request. I know this because the FL does not display on the web map and I get the console error:

dojo-lite.js:261 [esri.tasks.operations.pbfFeatureServiceParser]

  1. {name: "query:parsing-pbf", message: "Error while parsing FeatureSet PBF payload", details: {…}}
    1. details: {error: Error: Invalid data type! at c.skip (https://js.arcgis.com/4.15/dojo/dojo-lite.js:726:180) …}
    2. message: "Error while parsing FeatureSet PBF payload"
    3. name: "query:parsing-pbf"
    4. ...

Is this a bug in ArcGIS for JS API?

Is there a more robust way to change the FS query format from the client?

ArcGIS Enterprise Admin Professional, AWS Solutions Architect Professional
1 Solution

Accepted Solutions
YannCabon
Esri Contributor

Hi Shanon,

We don't have a proper way to disable pbf at the moment. You are on the right track to use interceptors.

It would work if you intercept the call to the service info, and override the supported query formats to only have JSON.

        esriConfig.request.interceptors.push({
          urls: /FeatureServer\/\d+$/,
          after: function (response) {
            response.data.supportedQueryFormats = "JSON";
          }
        });‍‍‍‍‍‍‍‍‍‍‍‍‍

Cheers

Yann

View solution in original post

5 Replies
YannCabon
Esri Contributor

Hi Shanon,

We don't have a proper way to disable pbf at the moment. You are on the right track to use interceptors.

It would work if you intercept the call to the service info, and override the supported query formats to only have JSON.

        esriConfig.request.interceptors.push({
          urls: /FeatureServer\/\d+$/,
          after: function (response) {
            response.data.supportedQueryFormats = "JSON";
          }
        });‍‍‍‍‍‍‍‍‍‍‍‍‍

Cheers

Yann

viewprogisdev
New Contributor

@ArnoFiva @ShanonLoughton @YannCabon 
Does the interceptors solution you have provided work with JS API 3.x version?

0 Kudos
Noah-Sager
Esri Regular Contributor

@viewprogisdev - at 3x, we have a setRequestPreCallback method that is fairly similar. See here:

https://developers.arcgis.com/javascript/3/jsapi/esri.request-amd.html#esrirequest.setrequestprecall...

 

JeffPace1
New Contributor III

has this been addressed? We are having trouble serving pbf files.  WE need to disable from the server side as we cannot control what the application requests.

 

 

0 Kudos
LanceKirby2
Occasional Contributor II

@JeffPace1 @ShanonLoughton I am having a similar issue. Did either of you ever figure out a resolution?

0 Kudos