-
Notifications
You must be signed in to change notification settings - Fork 32
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
add stored query update (PUT) method #189
Conversation
The stardog PR was merged. |
The stored query update tests pass with a build of Stardog off |
@jmrog yep. will do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, but I'm not sure that I really like the fact that updateStoredQuery
will make additional requests when a stardogVersion
isn't supplied. To me, that seems like an unexpected side effect that people might perceive as a bug of some kind (and, in order to avoid that side effect, it imposes on all future users of stardog.js a requirement to provide a version string). Could we not just go ahead and make the new update request, and, if that fails, fall back to the delete+add flow? We could then let people override this when necessary (and go immediately to the delete+add flow) by specifying an optional boolean argument rather than a Stardog version, which they'd otherwise never have to specify going forward, e.g.:
const updateStoredQuery = (conn, storedQuery, params, useUpdate = true) => {
if (!useUpdate) {
// old add+delete flow
}
else {
// try update, then try add+delete
}
};
One potential downside to the above is that people using Stardog < 6.2.0 will have an extra update request that fails behind the scenes. But I think that's okay for a couple of reasons: 1) it encourages upgrading, and I think it's probably good for stardog.js to most closely track the current Stardog (and/or work best with current versions), 2) it has a very easy escape hatch that lets people avoid the behavior if it's really an issue, and 3) it automatically works in the best way possible without any additional requests for users of the current and future Stardog versions, so it will ultimately be making fewer requests, especially for up-to-date Stardog users (whereas the current way will always make a version request, indefinitely into the future, unless all users take the escape hatch of providing a version number -- in which case, the escape hatch we provide in my own suggestion is essentially the same).
FWIW, we've imposed minimum version requirements for stardog.js before (it's only supported for version 5+) so it's also open to us to release a version with a new compatibility notice (but I'd prefer doing that only for major Stardog versions, not point releases). We probably should at least note that the method performs best with Stardog 6.2.0+.
Any thoughts on that @brianru or @neptunian ?
This would be okay here, but probably not great. The reason is that the version number node uses is the version of node itself. Here, it would actually have to be the version of Stardog that the method works with (e.g., 6.2.0+) rather than the version of stardog.js. It doesn't seem unlikely that that would confuse some people. It would also mean that people could get a version of stardog.js with methods available that simply don't work for them, which is another difference to the node case (where, if you don't have that node version, the method simply doesn't exist). |
@jmrog I'm good with your approach. In summary:
|
@jmrog ready for review again! |
lib/index.d.ts
Outdated
*/ | ||
function update(conn: Connection, config: StoredQueryOptions, params?: object): Promise<HTTP.Body> | ||
function update(conn: Connection, config: StoredQueryOptions, params?: object, useUpdateMethod?: boolean): Promise<HTTP.Body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing for update function seems off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment also says Default: false
when the default is actually true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of comments.
lib/index.d.ts
Outdated
*/ | ||
function update(conn: Connection, config: StoredQueryOptions, params?: object): Promise<HTTP.Body> | ||
function update(conn: Connection, config: StoredQueryOptions, params?: object, useUpdateMethod?: boolean): Promise<HTTP.Body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment also says Default: false
when the default is actually true
.
const replace = (conn, storedQuery, params) => | ||
deleteStoredQuery(conn, storedQuery.name).then(deleteResponse => { | ||
// Update creates when the query did not already exist | ||
if (deleteResponse.status === 404 || deleteResponse.ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check necessary? It seems like we create on both failure and success, so maybe we don't need to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to distinguish between 404 failures and non-404 failures. If it's a 404 I assume it means the query didn't exist and we can continue. Otherwise who knows what's happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. 👍
lib/response-transforms.js
Outdated
response.body = null; | ||
} | ||
} else if (res.text) { | ||
// 204 responses have `body: null` and no `text` method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment right? Can you please double-check? A fetch response should always have a .text
method; if it doesn't, there's likely a bug somewhere (e.g., the fetch response
itself isn't actually being passed in here, but something else is). (Relevant docs here: https://developer.mozilla.org/en-US/docs/Web/API/Response)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was definitely seeing this behavior the other day..I had to make this change for the tests to pass. But of course I'm not seeing that behavior now. Double checking with stardog 6.2.1 vs 6.1.3 (I was switching between the 2 at the time).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, it's because we've picked certain fields from the previous response isn't it..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have to reorder the promise then
s. Fix will be up shortly.
@brianru If it's okay with you, I'm going to merge this into the |
sounds good @jmrog ! |
Great, I'll do it momentarily. |
Rebased this on |
depends on this Stardog PR https://github.com/stardog-union/stardog/pull/7217 (merged and released)