Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 25, 2023
1 parent d33877c commit b8f16a4
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/empty-beans-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/utils': patch
---

Use `fetch` for reading files from the file system instead of `fs`
5 changes: 5 additions & 0 deletions .changeset/happy-ants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/cross-helpers': patch
---

Drop react-native dependency
5 changes: 5 additions & 0 deletions .changeset/rich-trees-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/types': patch
---

Update types
4 changes: 1 addition & 3 deletions packages/cross-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
"graphql": "*"
},
"dependencies": {
"path-browserify": "1.0.1",
"react-native-fs": "2.20.0",
"react-native-path": "0.0.5"
"path-browserify": "1.0.1"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 6 additions & 2 deletions packages/cross-helpers/react-native.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports.fs = require('react-native-fs');
module.exports.path = require('react-native-path');
try {
module.exports.fs = require('react-native-fs');
module.exports.path = require('react-native-path');
} catch (e) {
console.error('react-native-fs and react-native-path are required for react-native');
}
module.exports.path.join = (...args) =>
module.exports.path.normalize(args.filter(x => !!x).join('/'));

Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"type": "string"
},
"lazyConnect": {
"type": "boolean"
"type": "boolean",
"description": "Flag to indicate lazyConnect value for Redis client.\n\n@default: true"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,11 @@ export interface RedisConfig {
port?: string;
password?: string;
url?: string;
/**
* Flag to indicate lazyConnect value for Redis client.
*
* @default: true
*/
lazyConnect?: boolean;
}
export interface PubSubConfig {
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@graphql-mesh/string-interpolation": "^0.5.1",
"@graphql-tools/delegate": "^10.0.0",
"@whatwg-node/fetch": "^0.9.13",
"dset": "^3.1.2",
"js-yaml": "^4.1.0",
"lodash.get": "^4.4.2",
Expand All @@ -51,8 +52,7 @@
"@apollo/server": "4.9.3",
"@types/js-yaml": "4.0.6",
"@types/lodash.topath": "4.5.7",
"@types/object-hash": "3.0.4",
"@whatwg-node/fetch": "0.9.13"
"@types/object-hash": "3.0.4"
},
"publishConfig": {
"access": "public",
Expand Down
19 changes: 12 additions & 7 deletions packages/utils/src/read-file-or-url.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DEFAULT_SCHEMA, load as loadYamlFromJsYaml, Schema, Type } from 'js-yaml';
import { fs, path as pathModule } from '@graphql-mesh/cross-helpers';
import { ImportFn, Logger, MeshFetch, MeshFetchRequestInit } from '@graphql-mesh/types';
import { URL } from '@whatwg-node/fetch';
import { loadFromModuleExportExpression } from './load-from-module-export-expression.js';

export interface ReadFileOrUrlOptions extends MeshFetchRequestInit {
Expand All @@ -13,7 +14,7 @@ export interface ReadFileOrUrlOptions extends MeshFetchRequestInit {
}

export function isUrl(str: string): boolean {
return /^https?:\/\//.test(str);
return /^https?:\/\//.test(str) || /^file:\/\//.test(str);
}

export async function readFileOrUrl<T>(
Expand Down Expand Up @@ -80,7 +81,7 @@ export function loadYaml(filepath: string, content: string, logger: Logger): any

export async function readFile<T>(
fileExpression: string,
{ allowUnknownExtensions, cwd, fallbackFormat, importFn, logger }: ReadFileOrUrlOptions,
{ allowUnknownExtensions, cwd, fallbackFormat, importFn, logger, fetch }: ReadFileOrUrlOptions,
): Promise<T> {
const [filePath] = fileExpression.split('#');
if (/js$/.test(filePath) || /ts$/.test(filePath)) {
Expand All @@ -91,18 +92,22 @@ export async function readFile<T>(
});
}
const actualPath = pathModule.isAbsolute(filePath) ? filePath : pathModule.join(cwd, filePath);
const rawResult = await fs.promises.readFile(actualPath, 'utf-8');
const url = new URL(`file:///${actualPath}`);
const res = await fetch(url.href);
if (/json$/.test(actualPath)) {
return JSON.parse(rawResult);
return res.json();
}
if (/yaml$/.test(actualPath) || /yml$/.test(actualPath)) {
const rawResult = await res.text();
return loadYaml(actualPath, rawResult, logger);
} else if (fallbackFormat) {
switch (fallbackFormat) {
case 'json':
return JSON.parse(rawResult);
case 'yaml':
return res.json();
case 'yaml': {
const rawResult = await res.text();
return loadYaml(actualPath, rawResult, logger);
}
case 'ts':
case 'js':
return importFn(actualPath);
Expand All @@ -113,7 +118,7 @@ export async function readFile<T>(
`the correct extension (i.e. '.json', '.yaml', or '.yml).`,
);
}
return rawResult as unknown as T;
return res.text() as unknown as T;
}

export async function readUrl<T>(path: string, config: ReadFileOrUrlOptions): Promise<T> {
Expand Down
4 changes: 3 additions & 1 deletion website/src/generated-markdown/RedisConfig.generated.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* `port` (type: `String`)
* `password` (type: `String`)
* `url` (type: `String`)
* `lazyConnect` (type: `Boolean`)
* `lazyConnect` (type: `Boolean`) - Flag to indicate lazyConnect value for Redis client.

@default: true
30 changes: 6 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6970,7 +6970,7 @@
resolved "https://registry.yarnpkg.com/@whatwg-node/events/-/events-0.1.1.tgz#0ca718508249419587e130da26d40e29d99b5356"
integrity sha512-AyQEn5hIPV7Ze+xFoXVU3QTHXVbWPrzaOkxtENMPMuNL6VVHrp4hHfDt9nrQpjO7BgvuM95dMtkycX5M/DZR3w==

"@whatwg-node/[email protected]", "@whatwg-node/fetch@^0.9.0", "@whatwg-node/fetch@^0.9.10", "@whatwg-node/fetch@^0.9.4", "@whatwg-node/fetch@^0.9.7":
"@whatwg-node/[email protected]", "@whatwg-node/fetch@^0.9.0", "@whatwg-node/fetch@^0.9.10", "@whatwg-node/fetch@^0.9.13", "@whatwg-node/fetch@^0.9.4", "@whatwg-node/fetch@^0.9.7":
version "0.9.13"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.9.13.tgz#1d084cd546b9cd425ae89cbb1252a3e47a9a2e1c"
integrity sha512-PPtMwhjtS96XROnSpowCQM85gCUG2m7AXZFw0PZlGbhzx2GK7f2iOXilfgIJ0uSlCuuGbOIzfouISkA7C4FJOw==
Expand Down Expand Up @@ -8038,11 +8038,6 @@ balanced-match@^1.0.0:
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee"
integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==

base-64@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA==

base64-js@^1.1.2, base64-js@^1.3.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
Expand Down Expand Up @@ -19580,19 +19575,6 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==

[email protected]:
version "2.20.0"
resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.20.0.tgz#05a9362b473bfc0910772c0acbb73a78dbc810f6"
integrity sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ==
dependencies:
base-64 "^0.1.0"
utf8 "^3.0.0"

[email protected]:
version "0.0.5"
resolved "https://registry.yarnpkg.com/react-native-path/-/react-native-path-0.0.5.tgz#a04e4b73a535a8a7cf15c6e760e27db7789afb13"
integrity sha512-WJr256xBquk7X2O83QYWKqgLg43Zg3SrgjPc/kr0gCD2LoXA+2L72BW4cmstH12GbGeutqs/eXk3jgDQ2iCSvQ==

[email protected]:
version "8.2.0"
resolved "https://registry.yarnpkg.com/react-paginate/-/react-paginate-8.2.0.tgz#947c3dcb444a6c16c1bcf8361871aa135baa3dcd"
Expand Down Expand Up @@ -22297,9 +22279,14 @@ typical@^5.2.0:
integrity sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg==

"uWebSockets.js@uNetworking/uWebSockets.js#semver:^20":
<<<<<<< HEAD
version "20.32.0"
uid "21c0e41a662c27bcc29b64f3e9d7f0bdaa6d7ee7"
resolved "https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/21c0e41a662c27bcc29b64f3e9d7f0bdaa6d7ee7"
=======
version "20.31.0"
resolved "https://codeload.github.com/uNetworking/uWebSockets.js/tar.gz/809b99d2d7d12e2cbf89b7135041e9b41ff84084"
>>>>>>> 8bfeec71d (Improvements)

ua-parser-js@^1.0.35:
version "1.0.36"
Expand Down Expand Up @@ -22678,11 +22665,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/use-debounce/-/use-debounce-9.0.4.tgz#51d25d856fbdfeb537553972ce3943b897f1ac85"
integrity sha512-6X8H/mikbrt0XE8e+JXRtZ8yYVvKkdYRfmIhWZYsP8rcNs9hk3APV8Ua2mFkKRLcJKVdnX2/Vwrmg2GWKUQEaQ==

utf8@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1"
integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ==

util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
Expand Down

0 comments on commit b8f16a4

Please sign in to comment.