Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jaydenseric/graphql-react
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v9.0.0
Choose a base ref
...
head repository: jaydenseric/graphql-react
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Dec 3, 2019

  1. Update dev dependencies.

    jaydenseric committed Dec 3, 2019
    Copy the full SHA
    c1ab767 View commit details
  2. Copy the full SHA
    3745cbe View commit details
  3. Version 9.1.0.

    jaydenseric committed Dec 3, 2019
    Copy the full SHA
    b69d98f View commit details

Commits on Dec 5, 2019

  1. Copy the full SHA
    5e327b1 View commit details
  2. Copy the full SHA
    84675f0 View commit details

Commits on Dec 6, 2019

  1. Updated dependencies.

    Particularly extract-files.
    jaydenseric committed Dec 6, 2019
    Copy the full SHA
    d36cbbc View commit details
  2. Tidy Babel configs.

    jaydenseric committed Dec 6, 2019
    Copy the full SHA
    315b68e View commit details
  3. Copy the full SHA
    9e41129 View commit details
  4. Valid Node.js ESM deep imports.

    Note that the injected Babel helper imports still require file extensions to work in Node.js, see: babel/babel#10549 (comment)
    jaydenseric committed Dec 6, 2019
    Copy the full SHA
    8d204ac View commit details
  5. Update Babel dependencies.

    This brings Node.js ESM support a baby step closer.
    jaydenseric committed Dec 6, 2019
    Copy the full SHA
    9960546 View commit details

Commits on Jan 28, 2020

  1. Copy the full SHA
    d79248d View commit details

Commits on Feb 2, 2020

  1. Copy the full SHA
    ea708f0 View commit details
  2. Copy the full SHA
    3cac3d9 View commit details

Commits on Feb 3, 2020

  1. Copy the full SHA
    9a099d1 View commit details

Commits on Mar 21, 2020

  1. Update dependencies.

    Includes a workaround for a Node.js ESM/CJS interoperability Babel bug: babel/babel#7998 .
    jaydenseric committed Mar 21, 2020
    Copy the full SHA
    11eb3a1 View commit details
  2. Copy the full SHA
    5438bee View commit details
  3. Copy the full SHA
    5ae172e View commit details

Commits on Mar 22, 2020

  1. Improved Babel config.

    Includes a workaround for babel/babel#8462 .
    jaydenseric committed Mar 22, 2020
    Copy the full SHA
    7185b9d View commit details

Commits on Mar 24, 2020

  1. Copy the full SHA
    96648f9 View commit details
  2. Update dependencies.

    jaydenseric committed Mar 24, 2020
    Copy the full SHA
    f8f1195 View commit details
  3. Copy the full SHA
    4035284 View commit details
  4. Copy the full SHA
    67c596a View commit details

Commits on Mar 25, 2020

  1. Copy the full SHA
    810893a View commit details
  2. Copy the full SHA
    3478676 View commit details
  3. Update the changelog.

    jaydenseric committed Mar 25, 2020
    Copy the full SHA
    3f5e57f View commit details
  4. Merge pull request #42 from Grsmto/fix/batch-update-odd-state

    Use ReactDOM.unstable_batchedUpdates in the useGraphQL React hook to reduce the number of renders when loading completes, fixing #38 .
    jaydenseric authored Mar 25, 2020
    Copy the full SHA
    79249bb View commit details
  5. Version 10.0.0.

    jaydenseric committed Mar 25, 2020
    Copy the full SHA
    71739ef View commit details

Commits on Mar 30, 2020

  1. Improve linting.

    jaydenseric committed Mar 30, 2020
    Copy the full SHA
    070c4cf View commit details

Commits on Apr 6, 2020

  1. Copy the full SHA
    e4b8ef4 View commit details

Commits on Apr 7, 2020

  1. Reconfigure size-limit.

    jaydenseric committed Apr 7, 2020
    Copy the full SHA
    f09ecb8 View commit details
  2. Copy the full SHA
    919393f View commit details

Commits on Apr 28, 2020

  1. Update dependencies.

    jaydenseric committed Apr 28, 2020
    Copy the full SHA
    9ca1625 View commit details
  2. Copy the full SHA
    8e0e2fd View commit details
  3. Copy the full SHA
    70bf6ec View commit details

Commits on May 3, 2020

  1. Update dependencies.

    jaydenseric committed May 3, 2020
    Copy the full SHA
    7e7f91c View commit details
  2. Copy the full SHA
    37086df View commit details
  3. Copy the full SHA
    3ab4dcd View commit details
  4. Copy the full SHA
    e0932c8 View commit details
  5. Update readme content.

    jaydenseric committed May 3, 2020
    Copy the full SHA
    8294a55 View commit details
  6. Version 11.0.0.

    jaydenseric committed May 3, 2020
    Copy the full SHA
    1bb884d View commit details

Commits on Jun 7, 2020

  1. Copy the full SHA
    54a1ba3 View commit details
  2. Copy the full SHA
    7f5b1d0 View commit details
  3. Update EditorConfig.

    jaydenseric committed Jun 7, 2020
    Copy the full SHA
    ad04c1f View commit details

Commits on Jun 8, 2020

  1. Update dependencies.

    jaydenseric committed Jun 8, 2020
    Copy the full SHA
    9d41329 View commit details
  2. Copy the full SHA
    c73ec65 View commit details
  3. Update Node.js support.

    jaydenseric committed Jun 8, 2020
    Copy the full SHA
    bfd238d View commit details
  4. Version 11.0.1.

    jaydenseric committed Jun 8, 2020
    Copy the full SHA
    f6d0de3 View commit details

Commits on Jul 19, 2020

  1. Copy the full SHA
    a874510 View commit details
  2. Update dependencies.

    jaydenseric committed Jul 19, 2020
    Copy the full SHA
    b194459 View commit details
  3. Copy the full SHA
    898a968 View commit details
Showing with 9,016 additions and 3,260 deletions.
  1. +1 −2 .editorconfig
  2. +0 −6 .eslintignore
  3. +29 −1 .eslintrc.json
  4. +1 −0 .github/funding.yml
  5. +5 −9 .github/workflows/ci.yml
  6. +0 −5 .gitignore
  7. +0 −5 .huskyrc.json
  8. +0 −4 .lintstagedrc.json
  9. +0 −2 .prettierignore
  10. +1 −3 .prettierrc.json
  11. +0 −14 .size-limit.json
  12. +5 −0 .vscode/settings.json
  13. +70 −0 Cache.mjs
  14. +70 −0 Cache.test.mjs
  15. +18 −0 CacheContext.mjs
  16. +38 −0 CacheContext.test.mjs
  17. +10 −0 HYDRATION_TIME_MS.mjs
  18. +20 −0 HYDRATION_TIME_MS.test.mjs
  19. +16 −0 HydrationTimeStampContext.mjs
  20. +44 −0 HydrationTimeStampContext.test.mjs
  21. +49 −0 Loading.mjs
  22. +51 −0 Loading.test.mjs
  23. +140 −0 LoadingCacheValue.mjs
  24. +571 −0 LoadingCacheValue.test.mjs
  25. +18 −0 LoadingContext.mjs
  26. +41 −0 LoadingContext.test.mjs
  27. +71 −0 Provider.mjs
  28. +106 −0 Provider.test.mjs
  29. +29 −0 cacheDelete.mjs
  30. +95 −0 cacheDelete.test.mjs
  31. +25 −0 cacheEntryDelete.mjs
  32. +78 −0 cacheEntryDelete.test.mjs
  33. +30 −0 cacheEntryPrune.mjs
  34. +120 −0 cacheEntryPrune.test.mjs
  35. +30 −0 cacheEntrySet.mjs
  36. +72 −0 cacheEntrySet.test.mjs
  37. +25 −0 cacheEntryStale.mjs
  38. +76 −0 cacheEntryStale.test.mjs
  39. +28 −0 cachePrune.mjs
  40. +123 −0 cachePrune.test.mjs
  41. +28 −0 cacheStale.mjs
  42. +97 −0 cacheStale.test.mjs
  43. +442 −2 changelog.md
  44. +195 −0 fetchGraphQL.mjs
  45. +1,006 −0 fetchGraphQL.test.mjs
  46. +70 −0 fetchOptionsGraphQL.mjs
  47. +57 −0 fetchOptionsGraphQL.test.mjs
  48. +11 −0 jsconfig.json
  49. +9 −0 license.md
  50. +98 −61 package.json
  51. +174 −755 readme.md
  52. +0 −7 size-limit-entries/browser.mjs
  53. +0 −8 size-limit-entries/server.mjs
  54. +0 −15 src/server/.babelrc.js
  55. +0 −1 src/server/index.mjs
  56. +0 −95 src/server/ssr.mjs
  57. +0 −16 src/test/.babelrc.js
  58. +0 −511 src/test/GraphQL.mjs
  59. +0 −60 src/test/graphqlFetchOptions.mjs
  60. +0 −43 src/test/hashObject.mjs
  61. +0 −42 src/test/helpers/createGraphQLKoaApp.mjs
  62. +0 −29 src/test/helpers/promisifyEvent.mjs
  63. +0 −6 src/test/helpers/sleep.mjs
  64. +0 −18 src/test/helpers/startServer.mjs
  65. +0 −92 src/test/ssr.mjs
  66. +0 −581 src/test/useGraphQL.mjs
  67. +0 −21 src/universal/.babelrc.js
  68. +0 −14 src/universal/FirstRenderDateContext.mjs
  69. +0 −244 src/universal/GraphQL.mjs
  70. +0 −26 src/universal/GraphQLContext.mjs
  71. +0 −44 src/universal/GraphQLProvider.mjs
  72. +0 −47 src/universal/graphqlFetchOptions.mjs
  73. +0 −59 src/universal/hashObject.mjs
  74. +0 −119 src/universal/index.mjs
  75. +0 −69 src/universal/reportCacheErrors.mjs
  76. +0 −224 src/universal/useGraphQL.mjs
  77. +20 −0 test/Deferred.mjs
  78. +56 −0 test/ReactHookTest.mjs
  79. +56 −0 test/assertBundleSize.mjs
  80. +22 −0 test/assertInstanceOf.mjs
  81. +38 −0 test/assertTypeOf.mjs
  82. +26 −0 test/createReactTestRenderer.mjs
  83. +27 −0 test/polyfillCustomEvent.mjs
  84. +9 −0 test/polyfillFile.mjs
  85. +15 −0 test/suppressReactRenderErrorConsoleOutput.mjs
  86. +135 −0 types.mjs
  87. +57 −0 useAutoAbortLoad.mjs
  88. +194 −0 useAutoAbortLoad.test.mjs
  89. +50 −0 useAutoLoad.mjs
  90. +181 −0 useAutoLoad.test.mjs
  91. +23 −0 useCache.mjs
  92. +105 −0 useCache.test.mjs
  93. +45 −0 useCacheEntry.mjs
  94. +289 −0 useCacheEntry.test.mjs
  95. +38 −0 useCacheEntryPrunePrevention.mjs
  96. +158 −0 useCacheEntryPrunePrevention.test.mjs
  97. +13 −0 useForceUpdate.mjs
  98. +54 −0 useForceUpdate.test.mjs
  99. +90 −0 useLoadGraphQL.mjs
  100. +566 −0 useLoadGraphQL.test.mjs
  101. +41 −0 useLoadOnDelete.mjs
  102. +268 −0 useLoadOnDelete.test.mjs
  103. +73 −0 useLoadOnMount.mjs
  104. +951 −0 useLoadOnMount.test.mjs
  105. +41 −0 useLoadOnStale.mjs
  106. +265 −0 useLoadOnStale.test.mjs
  107. +23 −0 useLoading.mjs
  108. +108 −0 useLoading.test.mjs
  109. +49 −0 useLoadingEntry.mjs
  110. +305 −0 useLoadingEntry.test.mjs
  111. +53 −0 useWaterfallLoad.mjs
  112. +279 −0 useWaterfallLoad.test.mjs
3 changes: 1 addition & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
max_line_length = 80
trim_trailing_whitespace = true
insert_final_newline = true
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

30 changes: 29 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
{
"extends": ["env"]
"extends": ["eslint:recommended", "plugin:react-hooks/recommended"],
"env": {
"es2022": true,
"node": true,
"browser": true
},
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": ["simple-import-sort"],
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error"
},
"overrides": [
{
"files": ["*.mjs"],
"parserOptions": {
"sourceType": "module"
},
"globals": {
"__dirname": "off",
"__filename": "off",
"exports": "off",
"module": "off",
"require": "off"
}
}
]
}
1 change: 1 addition & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: jaydenseric
14 changes: 5 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
name: CI
on: [push]
on: [push, workflow_dispatch]
jobs:
test:
name: Test with Node.js v${{ matrix.node }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node: ['8', '10', '12', '13']
node: ["18", "20", "22"]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- name: Setup Node.js v${{ matrix.node }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: npm install and test
run: |
npm install
npm test
env:
CI: true
run: npm install-test
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
node_modules
npm-debug.log
.DS_Store
/universal
/server
/test
.nyc_output
5 changes: 0 additions & 5 deletions .huskyrc.json

This file was deleted.

4 changes: 0 additions & 4 deletions .lintstagedrc.json

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
package.json
.nyc_output
tap-snapshots
4 changes: 1 addition & 3 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"proseWrap": "never",
"singleQuote": true,
"semi": false
"proseWrap": "never"
}
14 changes: 0 additions & 14 deletions .size-limit.json

This file was deleted.

5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"typescript.disableAutomaticTypeAcquisition": true,
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.tsdk": "node_modules/typescript/lib"
}
70 changes: 70 additions & 0 deletions Cache.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// @ts-check

/**
* Cache store.
* @see {@link CacheEventMap `CacheEventMap`} for a map of possible events.
*/
export default class Cache extends EventTarget {
/**
* @param {CacheStore} [store] Initial {@link Cache.store cache store}.
* Defaults to `{}`. Useful for hydrating cache data from a server side
* render prior to the initial client side render.
*/
constructor(store = {}) {
super();

if (typeof store !== "object" || !store || Array.isArray(store))
throw new TypeError("Constructor argument 1 `store` must be an object.");

/**
* Store of cache {@link CacheKey keys} and associated
* {@link CacheValue values}.
* @type {CacheStore}
*/
this.store = store;
}
}

/**
* Map of possible {@linkcode Cache} events. Note that the keys don’t match the
* dispatched event names that dynamically contain the associated
* {@link CacheKey cache key}.
* @typedef {object} CacheEventMap
* @prop {CustomEvent<CacheEventSetDetail>} set Signals that a
* {@link Cache.store cache store} entry was set. The event name starts with
* the {@link CacheKey cache key} of the set entry, followed by `/set`.
* @prop {CustomEvent} stale Signals that a {@link Cache.store cache store}
* entry is now stale (often due to a mutation) and should probably be
* reloaded. The event name starts with the
* {@link CacheKey cache key} of the stale entry, followed by `/stale`.
* @prop {CustomEvent} prune Signals that a {@link Cache.store cache store}
* entry will be deleted unless the event is canceled via
* `event.preventDefault()`. The event name starts with the
* {@link CacheKey cache key} of the entry being pruned, followed by `/prune`.
* @prop {CustomEvent} delete Signals that a {@link Cache.store cache store}
* entry was deleted. The event name starts with the
* {@link CacheKey cache key} of the deleted entry, followed by `/delete`.
*/

/**
* @typedef {object} CacheEventSetDetail
* @prop {CacheValue} cacheValue The set {@link CacheValue cache value}.
*/

/**
* Unique key to access a {@link CacheValue cache value}.
* @typedef {string} CacheKey
*/

/**
* {@link Cache.store Cache store} value. If server side rendering, it should
* be JSON serializable for client hydration. It should contain information
* about any errors that occurred during loading so they can be rendered, and if
* server side rendering, be hydrated on the client.
* @typedef {unknown} CacheValue
*/

/**
* Cache store.
* @typedef {{ [cacheKey: CacheKey]: CacheValue }} CacheStore
*/
70 changes: 70 additions & 0 deletions Cache.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// @ts-check

import "./test/polyfillCustomEvent.mjs";

import { deepStrictEqual, strictEqual, throws } from "node:assert";
import { describe, it } from "node:test";

import Cache from "./Cache.mjs";
import assertBundleSize from "./test/assertBundleSize.mjs";
import assertInstanceOf from "./test/assertInstanceOf.mjs";

describe("Class `Cache`.", { concurrency: true }, () => {
it("Bundle size.", async () => {
await assertBundleSize(new URL("./Cache.mjs", import.meta.url), 200);
});

it("Constructor argument 1 `store` not an object.", () => {
throws(() => {
new Cache(
// @ts-expect-error Testing invalid.
null,
);
}, new TypeError("Constructor argument 1 `store` must be an object."));
});

it("Constructor argument 1 `store` missing", () => {
const cache = new Cache();

deepStrictEqual(cache.store, {});
});

it("Constructor argument 1 `store` an object.", () => {
const initialStore = {
a: 1,
b: 2,
};
const cache = new Cache({ ...initialStore });

deepStrictEqual(cache.store, initialStore);
});

it("Events.", () => {
const cache = new Cache();

assertInstanceOf(cache, EventTarget);

/** @type {Event | null} */
let listenedEvent = null;

/** @type {EventListener} */
const listener = (event) => {
listenedEvent = event;
};

const eventName = "a";
const event = new CustomEvent(eventName);

cache.addEventListener(eventName, listener);
cache.dispatchEvent(event);

strictEqual(listenedEvent, event);

listenedEvent = null;

cache.removeEventListener(eventName, listener);
cache.dispatchEvent(new CustomEvent(eventName));

strictEqual(listenedEvent, null);
});
});
18 changes: 18 additions & 0 deletions CacheContext.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @ts-check

/** @import Cache from "./Cache.mjs" */

import React from "react";

/**
* [React context](https://reactjs.org/docs/context.html) for a
* {@linkcode Cache} instance.
* @type {React.Context<Cache | undefined>}
*/
const CacheContext = React.createContext(
/** @type {Cache | undefined} */ (undefined),
);

CacheContext.displayName = "CacheContext";

export default CacheContext;
38 changes: 38 additions & 0 deletions CacheContext.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check

import { strictEqual } from "node:assert";
import { describe, it } from "node:test";

import React from "react";

import Cache from "./Cache.mjs";
import CacheContext from "./CacheContext.mjs";
import assertBundleSize from "./test/assertBundleSize.mjs";
import createReactTestRenderer from "./test/createReactTestRenderer.mjs";

describe("React context `CacheContext`.", { concurrency: true }, () => {
it("Bundle size.", async () => {
await assertBundleSize(new URL("./CacheContext.mjs", import.meta.url), 120);
});

it("Used as a React context.", () => {
let contextValue;

function TestComponent() {
contextValue = React.useContext(CacheContext);
return null;
}

const value = new Cache();

createReactTestRenderer(
React.createElement(
CacheContext.Provider,
{ value },
React.createElement(TestComponent),
),
);

strictEqual(contextValue, value);
});
});
10 changes: 10 additions & 0 deletions HYDRATION_TIME_MS.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

/** @import useAutoLoad from "./useAutoLoad.mjs" */

/**
* Number of milliseconds after the first client render that’s considered the
* hydration time; during which the {@linkcode useAutoLoad} React hook won’t
* load if the cache entry is already populated.
*/
export default 1000;
20 changes: 20 additions & 0 deletions HYDRATION_TIME_MS.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-check

import { strictEqual } from "node:assert";
import { describe, it } from "node:test";

import HYDRATION_TIME_MS from "./HYDRATION_TIME_MS.mjs";
import assertBundleSize from "./test/assertBundleSize.mjs";

describe("Constant `HYDRATION_TIME_MS`.", { concurrency: true }, () => {
it("Bundle size.", async () => {
await assertBundleSize(
new URL("./HYDRATION_TIME_MS.mjs", import.meta.url),
65,
);
});

it("Value.", () => {
strictEqual(HYDRATION_TIME_MS, 1000);
});
});
16 changes: 16 additions & 0 deletions HydrationTimeStampContext.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check

import React from "react";

/**
* [React context](https://reactjs.org/docs/context.html) for the client side
* hydration {@link DOMHighResTimeStamp time stamp}.
* @type {React.Context<DOMHighResTimeStamp | undefined>}
*/
const HydrationTimeStampContext = React.createContext(
/** @type {DOMHighResTimeStamp | undefined} */ (undefined),
);

HydrationTimeStampContext.displayName = "HydrationTimeStampContext";

export default HydrationTimeStampContext;
Loading