Skip to content

query.get is using find which creates issues with BeforeFind #5006

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

Closed
mullwaden opened this issue Aug 27, 2018 · 8 comments
Closed

query.get is using find which creates issues with BeforeFind #5006

mullwaden opened this issue Aug 27, 2018 · 8 comments

Comments

@mullwaden
Copy link

Issue Description

I am having issues with the isGet parameter in the beforeFind trigger. While my query is definitely a .get isGet does not seem to be set correctly.

  • When I run the following command in the front-end (new Parse.Query('BusinessUnit')).get('HlNbtoSUiR') the parse-js-sdk creates a POST request to http://localhost:1337/parse/classes/BusinessUnit.
  • This triggers handleFind (not handleGet) in ClassesRouter.js in the back-end. This is likely because handleGet expects a route with the following format /classes/:className/:objectId but as the get in the frontend uses .first it ends up calling /classes/:className
  • ClassesRouter.js then triggers find() in rest.js which in turn calls the beforeFind trigger with isGet set to false

Relevant files:
https://github.com/parse-community/Parse-SDK-JS/blob/master/src/ParseQuery.js
https://github.com/parse-community/parse-server/blob/master/src/Routers/ClassesRouter.js
https://github.com/parse-community/parse-server/blob/master/src/rest.js

Steps to reproduce

Run any query.get command and look at the network tab

Expected Results

A .get query in the frontend GETs on /classes/:className/:objectId

Actual Outcome

A .get query in the frontend POSTs on /classes/:className
(the POST vs GET bit is probably fine, but the route seems off)

@flovilmart
Copy link
Contributor

Can you provide the logs when running with VERBOSELY=1 p’ease?

@mullwaden
Copy link
Author

Sure thing, so when i run the following command (new Parse.Query('BusinessUnit')).get('HlNbtoSUiR')

It prints:

[1] verbose: REQUEST for [GET] /parse/classes/BusinessUnit: {
[1]   "where": {
[1]     "objectId": "HlNbtoSUiR"
[1]   },
[1]   "limit": 1
[1] } method=GET, url=/parse/classes/BusinessUnit, host=localhost:1337, connection=keep-alive, content-length=228, pragma=no-cache, cache-control=no-cache, origin=http://localhost:3003, user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36, content-type=text/plain, accept=*/*, referer=http://localhost:3003/active-search-list, accept-encoding=gzip, deflate, br, accept-language=en-US,en;q=0.9, objectId=HlNbtoSUiR, limit=1

in beforeFind for BusinessUnit I get the following parameters:

{
  "triggerName": "beforeFind",
  "query": {
    "where": {
      "objectId": "HlNbtoSUiR"
    },
    "limit": 1
  },
  "master": false,
  "count": false,
  "log": { ... },
  "isGet": false,
  "headers": {
    "host": "localhost:1337",
    "connection": "keep-alive",
    "content-length": "228",
    "pragma": "no-cache",
    "cache-control": "no-cache",
    "origin": "http://localhost:3003",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
    "content-type": "text/plain",
    "accept": "*/*",
    "referer": "http://localhost:3003/active-search-list",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "en-US,en;q=0.9"
  },
  "ip": "::1",
  "user": { ... },
  "installationId": "ffbaf088-79e9-89f6-5afa-19f0ba39639c"
}

@mullwaden
Copy link
Author

Made a little workaround in my beforeFind which works but doesnt feel quite right:

  let isGetFixed = isGet;

  if (!isGet) {
    isGetFixed = query._where && isParseId(query._where.objectId) && query._limit === 1;
  }

@flovilmart
Copy link
Contributor

Closing as behaving as expected. The isGet denotes if using the endpoint with objectId, not a query on the objectId. Please update your code accordingly

@mullwaden
Copy link
Author

Hmm ok, how would I write it correctly in the front-end? Seems strange to me that .get is not isGet

@flovilmart
Copy link
Contributor

Use Parse.Object() ‘s [fetch]
(http://parseplatform.org/Parse-SDK-JS/api/v2.0.2/Parse.Object.html#fetch) instead of a query. Perhaps isGet is not the right term, or is confusing, but I won’t do what you expect it to do.

@mullwaden
Copy link
Author

I see, maybe isFetch would be a better name - anyhow easy to work around, just confusing

@flovilmart
Copy link
Contributor

yeah maybe. But we won't consider this change at the moment.

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

4 participants