-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Vendor "graphql-client" and bump "is-my-json-valid" to 2.20.6 #3497
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: ISC | ||
// Copyright (c) 2016-2018, Simon Nord and other contributors | ||
// https://github.com/nordsimon/graphql-client/blob/f8d1dcba8a65f290e35b71c883a18094594d6d5a/index.js | ||
|
||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (c) 2021-present, Contributors to the rxdb project | ||
|
||
export interface GraphQLError { | ||
message: string; | ||
locations: Array<{ | ||
line: number; | ||
column: number; | ||
}>; | ||
path: string[]; | ||
} | ||
|
||
export type GraphQLErrors = Array<GraphQLError>; | ||
|
||
function highlightQuery(query: string, errors: GraphQLErrors) { | ||
const locations = errors | ||
.map((e) => { | ||
return e.locations; | ||
}) | ||
.reduce((a, b) => { | ||
return a.concat(b); | ||
}, []); | ||
|
||
let queryHighlight = ''; | ||
|
||
query.split('\n').forEach((row, index) => { | ||
const line = index + 1; | ||
const lineErrors = locations.filter((loc) => { | ||
return loc && loc.line === line; | ||
}); | ||
|
||
queryHighlight += row + '\n'; | ||
|
||
if (lineErrors.length) { | ||
const errorHighlight: string[] = []; | ||
|
||
lineErrors.forEach((lineError) => { | ||
for (let i = 0; i < 8; i++) { | ||
errorHighlight[lineError.column + i] = '~'; | ||
} | ||
}); | ||
|
||
for (let i = 0; i < errorHighlight.length; i++) { | ||
queryHighlight += errorHighlight[i] || ' '; | ||
} | ||
queryHighlight += '\n'; | ||
} | ||
}); | ||
|
||
return queryHighlight; | ||
} | ||
|
||
export interface GraphQLClientParams { | ||
url: string; | ||
headers?: HeadersInit; | ||
credentials?: RequestCredentials; | ||
} | ||
|
||
function GraphQLClient(params: GraphQLClientParams) { | ||
require('isomorphic-fetch'); | ||
if (!params.url) throw new Error('Missing url parameter'); | ||
|
||
const headers = new Headers(params.headers || {}); | ||
headers.append('Content-Type', 'application/json'); | ||
|
||
return { | ||
query: ( | ||
query: string, | ||
variables?: Record<string, unknown>, | ||
onResponse?: (req: Request, res: Response) => void | ||
) => { | ||
const req = new Request(params.url, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
query: query, | ||
variables: variables, | ||
}), | ||
headers: headers, | ||
credentials: params.credentials, | ||
}); | ||
|
||
return fetch(req) | ||
.then((res) => { | ||
onResponse && onResponse(req, res); | ||
|
||
return res.json(); | ||
}) | ||
.then((body) => { | ||
if (body.errors && body.errors.length) { | ||
body.highlightQuery = highlightQuery( | ||
query, | ||
body.errors | ||
); | ||
} | ||
|
||
return body; | ||
}); | ||
}, | ||
}; | ||
} | ||
|
||
export default GraphQLClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please do not use version ranges.
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.
It is not a good idea for a library to pin dependencies. It prevents dependents from bumping packages, should the need arise, or if there is a security issue. In other cases, it might lead to out of sync dependency trees. Last, if you are busy for a period of time and can't publish new versions, the pinned dependencies will remain a PITA for all dependents.
Anyways, I will leave that decision to you. I pushed the commit you requested.
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.
Yes all this is true in theory. But in practice, stuff breaks all the time, it did so in the past and it will so in the future.
When a new version is released, the renovate bot will make a PR to this repo with the updated version.
I know that this is not the common opinion, but I had this discussion in the past so often.
When you add a version range and someone runs
npm install rxdb
, you cannot predict which subdependency version will be installed. And then they come and create issues because nothing works for them. Also a package-lock would not help because the package-lock is not part of the npm package.