Skip to content
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
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/graphql/test/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Selector
} from 'testcafe';
import AsyncTestUtil from 'async-test-util';
import GraphQLClient from 'graphql-client';
import GraphQLClient from 'rxdb/graphql-client';
import {
GRAPHQL_PORT
} from '../shared';
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@
"event-reduce-js": "1.4.1",
"express": "4.17.1",
"get-graphql-from-jsonschema": "8.0.16",
"graphql-client": "2.0.1",
"is-electron": "2.2.0",
"is-my-json-valid": "2.20.5",
"is-my-json-valid": "^2.20.6",
"isomorphic-fetch": "^3.0.0",
Copy link
Owner

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.

Copy link
Author

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.

Copy link
Owner

@pubkey pubkey Nov 14, 2021

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.

"jsonschema-key-compression": "1.6.0",
"lokijs": "1.5.12",
"modifyjs": "0.3.1",
Expand Down
106 changes: 106 additions & 0 deletions src/graphql-client.ts
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;
2 changes: 1 addition & 1 deletion src/plugins/replication-graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import {
filter
} from 'rxjs/operators';
import GraphQLClient from 'graphql-client';
import GraphQLClient from '../../graphql-client';
import objectPath from 'object-path';
import {
promiseWait,
Expand Down
1 change: 0 additions & 1 deletion src/types/modules/graphql-client.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/helper/graphql-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @link https://graphql.org/graphql-js/running-an-express-graphql-server/
*/

import graphQlClient from 'graphql-client';
import graphQlClient from '../../graphql-client';
import { PubSub } from 'graphql-subscriptions';
import {
buildSchema,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/replication-graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert';
import AsyncTestUtil, {
clone, wait
} from 'async-test-util';
import GraphQLClient from 'graphql-client';
import GraphQLClient from '../../graphql-client';

import {
first
Expand Down