Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"plugins": ["prettier"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed to fully defer to 4c cli's pedantic library for linting/formatting

"extends": [
"4catalyzer",
"4catalyzer-jest",
Expand All @@ -10,8 +9,14 @@
"node": true
},
"rules": {
"prettier/prettier": "error",
"global-require": "off",
"import/no-dynamic-require": "off"
"import/no-dynamic-require": "off",
"no-empty-function": "off",
"@typescript-eslint/no-empty-function": [
"error",
{
"allow": ["constructors"]
}
]
Comment on lines +14 to +20
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typical config to allow abstract class constructor definitions, I believe

}
}
8 changes: 5 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [22.x]
steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: corepack enable
- run: yarn install --immutable
- run: yarn test --coverage
- run: node_modules/.bin/codecov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ typings/
# Output of 'npm pack'
*.tgz

# Yarn Integrity file
# Yarn
.yarn-integrity
.yarn/install-state.gz

# dotenv environment variables file
.env
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
50 changes: 24 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@4c/graphql-node-resource",
"version": "5.1.0",
"packageManager": "[email protected]",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this and corepack to ensure the proper yarn version is used. This is a typical setup, I believe. Open to suggestions, though

"main": "lib/index.js",
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,51 +41,48 @@
"conventionalCommits": true
},
"dependencies": {
"@types/lodash": "^4.14.178",
"@types/node": "^17.0.8",
"@types/node-fetch": "^2.5.12",
"@types/pluralize": "^0.0.29",
"dataloader": "^2.0.0",
"express": "^4.17.3",
"form-data": "^4.0.4",
"@types/lodash": "^4.17.21",
"@types/node": "^25.0.3",
"@types/node-fetch": "^2.6.13",
"@types/pluralize": "^0.0.33",
"dataloader": "^2.2.3",
"express": "^5.2.1",
"form-data": "^4.0.5",
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"pluralize": "^8.0.0",
"utility-types": "^3.10.0"
"utility-types": "^3.11.0"
},
"peerDependencies": {
"graphql": ">=14.0.0",
"graphql-relay": ">=0.7.0"
},
"devDependencies": {
"@4c/babel-preset": "^9.1.0",
"@4c/cli": "^3.0.1",
"@4c/babel-preset": "^10.2.1",
"@4c/cli": "^4.0.4",
"@4c/jest-preset": "^1.8.1",
"@4c/prettier-config": "^1.1.0",
"@4c/tsconfig": "^0.4.1",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^27.5.2",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"codecov": "^3.8.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use codecov's GHA (https://github.com/codecov/codecov-action) instead

"@babel/preset-typescript": "^7.28.5",
"@types/jest": "^30.0.0",
"@typescript-eslint/eslint-plugin": "^8.51.0",
"@typescript-eslint/parser": "^8.51.0",
"eslint-config-4catalyzer": "^1.5.0",
"eslint-config-4catalyzer-jest": "^2.3.0",
"eslint-config-4catalyzer-typescript": "^3.3.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^25.7.0",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-jest": "^29.12.1",
"fetch-mock": "^9.11.0",
"graphql": "^16.6.0",
"graphql-relay": "^0.10.0",
"hookem": "^2.0.1",
"jest": "^27.5.1",
"lint-staged": "^12.5.0",
"prettier": "^2.7.1",
"typescript": "^4.7.4"
"graphql": "^16.12.0",
"graphql-relay": "^0.10.2",
"hookem": "^3.0.4",
"jest": "^30.2.0",
"lint-staged": "^16.2.7",
"typescript": "^5.9.3"
},
"engines": {
"node": ">=v12.0.0"
"node": ">=v20.0.0"
},
"bugs": {
"url": "https://github.com/4Catalyzer/graphql-node-resource/issues"
Expand Down
12 changes: 6 additions & 6 deletions src/api/HttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import flatten from 'lodash/flatten';
import omit from 'lodash/omit';
import pick from 'lodash/pick';

import { HttpMethod } from './fetch';
import { Maybe, Obj } from '../utils/typing';
import urlJoin from '../utils/urlJoin';
import { HttpMethod } from './fetch';

const PAGINATION_ARG_KEYS = Object.keys(forwardConnectionArgs);

Expand Down Expand Up @@ -60,11 +60,11 @@ export default abstract class HttpApi {
/** The serializer and deserializer used for query parameters */
readonly qs: QueryString = querystring;

/**
DataLoader requests with many keys will be split into multiple
requests to avoid hitting URL size limits. The default works well for
chunking UUID keys
*/
/**
* DataLoader requests with many keys will be split into multiple
* requests to avoid hitting URL size limits. The default works well for
* chunking UUID keys
*/
readonly numKeysPerChunk: number = 25;

constructor({ apiBase, origin, externalOrigin }: HttpApiOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/api/HttpError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default class HttpError extends Error {
errors: this.errors,
},
};
} catch (e) {
} catch {
this.errors = [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/HttpResource.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Resource from './Resource';
import HttpApi, { Args, Data } from '../api/HttpApi';
import { Context } from '../types/Context';
import { Maybe, Obj } from '../utils/typing';
import urlJoin from '../utils/urlJoin';
import Resource from './Resource';

export type Endpoint = string | ((id?: string) => string);

Expand Down
2 changes: 1 addition & 1 deletion src/resources/PaginatedHttpResource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HttpApi, { Args } from '../api/HttpApi';
import HttpResource from './HttpResource';
import HttpApi, { Args } from '../api/HttpApi';

export default class PaginatedHttpResource<
TApi extends HttpApi = HttpApi,
Expand Down
2 changes: 1 addition & 1 deletion src/types/ResourceCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Resource from '../resources/Resource';
import { Context, RESOURCE_CACHE_KEY } from './Context';
import Resource from '../resources/Resource';

export default class ResourceCache {
cache = new WeakMap<any, Map<string, Resource<any>>>();
Expand Down
3 changes: 2 additions & 1 deletion src/types/createResolve.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { GraphQLFieldConfig, GraphQLFieldResolver } from 'graphql';

import NodeType from './NodeType';
import { Obj } from '../utils/typing';

export default function createResolve<
TSource,
TSource extends Obj,
TContext,
TField extends string,
>(
Expand Down
2 changes: 1 addition & 1 deletion test/HttpResource.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { connectionFromArray } from 'graphql-relay';
import mockedFetch from 'node-fetch';

import HttpResource from '../src/resources/HttpResource';
import { TestHttpApi } from './helpers';
import HttpResource from '../src/resources/HttpResource';

describe('HttpResource', () => {
let mockContext;
Expand Down
2 changes: 1 addition & 1 deletion test/NodeType.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
import mockedFetch from 'node-fetch';

import { HttpResource } from '../src';
import { MockContext, TestHttpApi, TestHttpResource } from './helpers';
import { getConfig, setup } from '../src/config';
import NodeType from '../src/types/NodeType';
import createResolve from '../src/types/createResolve';
import { MockContext, TestHttpApi, TestHttpResource } from './helpers';

function mockResponses() {
mockedFetch.getOnce('https://gateway/v1/widgets/1', {
Expand Down
4 changes: 2 additions & 2 deletions test/PaginatedHttpResource.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import mockedFetch from 'node-fetch';

import { HttpContext, RESOURCE_CACHE_KEY } from '../src';
import PaginatedHttpResource from '../src/resources/PaginatedHttpResource';
import { TestHttpApi } from './helpers';
import PaginatedHttpResource from '../src/resources/PaginatedHttpResource';

describe('PaginatedHttpResource', () => {
let mockContext: HttpContext<any>;
Expand Down Expand Up @@ -163,7 +163,7 @@ describe('PaginatedHttpResource', () => {

await expect(
resource.getConnection({ after: 'asfs', before: 'afasf' }),
).rejects.toThrowError(
).rejects.toThrow(
'`after` and `before` cursors cannot be specified together',
);
});
Expand Down
4 changes: 3 additions & 1 deletion test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('fetch', () => {
],
});

expect(mockedFetch.lastCall()![1].body instanceof FormData).toEqual(true);
const lastCall = mockedFetch.lastCall();
const body = lastCall?.[1]?.body;
expect(body instanceof FormData).toEqual(true);
});
});
Loading