Skip to content

Commit beed915

Browse files
committed
extract common hooks
1 parent 9f0bcf5 commit beed915

File tree

173 files changed

+5176
-4260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+5176
-4260
lines changed

jest.config.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
module.exports = {
22
projects: [
33
"<rootDir>/packages/api-client-core/jest.config.js",
4+
"<rootDir>/packages/client-hooks/jest.config.js",
45
"<rootDir>/packages/core/jest.config.js",
6+
"<rootDir>/packages/preact/jest.config.js",
57
"<rootDir>/packages/react/jest.config.js",
8+
"<rootDir>/packages/react-bigcommerce/jest.config.js",
69
"<rootDir>/packages/react-shopify-app-bridge/jest.config.js",
7-
"<rootDir>/packages/tiny-graphql-query-compiler/jest.config.js",
810
"<rootDir>/packages/shopify-extensions/jest.config.js",
9-
"<rootDir>/packages/react-bigcommerce/jest.config.js",
11+
"<rootDir>/packages/tiny-graphql-query-compiler/jest.config.js",
12+
"<rootDir>/packages/utils/jest.config.js",
1013
],
1114
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"lint:eslint": "NODE_OPTIONS=\"--max-old-space-size=4096\" eslint --quiet --ext ts,tsx packages scripts",
1313
"lint:fix": "NODE_OPTIONS=\"--max-old-space-size=4096\" prettier --write --check \"(packages|scripts)/**/*.{js,ts,tsx}\" && eslint --ext ts,tsx --fix packages scripts",
1414
"typecheck": "pnpm -r --no-bail run --if-present typecheck",
15-
"build": "pnpm -r --no-bail run --if-present build",
15+
"build": "pnpm --filter=@gadgetinc/utils build && pnpm -r --no-bail run --if-present build",
1616
"prerelease": "pnpm -r --no-bail run --if-present prerelease",
1717
"watch": "run-p --print-label watch:*",
1818
"watch:client": "pnpm --filter=@gadgetinc/api-client-core watch",

packages/api-client-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"prerelease": "gitpkg publish"
2929
},
3030
"dependencies": {
31+
"@gadgetinc/utils": "^0.1.0",
3132
"@0no-co/graphql.web": "^1.0.4",
3233
"@n1ru4l/graphql-live-query": "^0.10.0",
3334
"@n1ru4l/json-patch-plus": "^0.2.0",

packages/api-client-core/src/GadgetRecord.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { isEqual, toPrimitiveObject } from "@gadgetinc/utils";
12
import { klona as cloneDeep } from "klona";
23
import type { Jsonify } from "type-fest";
3-
import { isEqual, toPrimitiveObject } from "./support.js";
44

55
export enum ChangeTracking {
66
SinceLoaded,

packages/api-client-core/src/GadgetRecordList.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* eslint-disable no-throw-literal */
22
/* eslint-disable @typescript-eslint/require-await */
3+
import { GadgetClientError, GadgetOperationError } from "@gadgetinc/utils";
34
import type { Jsonify } from "type-fest";
45
import type { GadgetRecord, RecordShape } from "./GadgetRecord.js";
56
import type { InternalModelManager } from "./InternalModelManager.js";
67
import type { AnyModelManager } from "./ModelManager.js";
7-
import { GadgetClientError, GadgetOperationError } from "./support.js";
88
import type { PaginateOptions } from "./types.js";
99

10-
type PaginationConfig = {
10+
export type PaginationConfig = {
1111
pageInfo: { hasNextPage: boolean; hasPreviousPage: boolean; startCursor: string; endCursor: string };
1212
options?: PaginateOptions;
1313
};

packages/api-client-core/src/GadgetTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { assertOperationSuccess } from "@gadgetinc/utils";
12
import type { Client } from "@urql/core";
23
import type { Client as SubscriptionClient } from "graphql-ws";
3-
import { assertOperationSuccess } from "./support.js";
44

55
/** Represents the error thrown when a transaction is explicity rolled back, sometimes due to another inner error */
66
export class TransactionRolledBack extends Error {}

packages/api-client-core/src/InternalModelManager.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { Call, Var, compileWithVariableValues } from "tiny-graphql-query-compiler";
2-
import type { GadgetConnection } from "./GadgetConnection.js";
3-
import type { GadgetRecord, RecordShape } from "./GadgetRecord.js";
4-
import { GadgetRecordList } from "./GadgetRecordList.js";
51
import {
6-
ErrorsSelection,
72
GadgetClientError,
83
GadgetOperationError,
94
assert,
@@ -13,15 +8,16 @@ import {
138
camelize,
149
capitalizeIdentifier,
1510
filterTypeName,
16-
hydrateConnection,
17-
hydrateRecord,
18-
hydrateRecordArray,
19-
hydrationSelection,
2011
namespaceDataPath,
2112
namespacedGraphQLTypeName,
2213
namespacify,
2314
sortTypeName,
24-
} from "./support.js";
15+
} from "@gadgetinc/utils";
16+
import { Call, Var, compileWithVariableValues } from "tiny-graphql-query-compiler";
17+
import type { GadgetConnection } from "./GadgetConnection.js";
18+
import type { GadgetRecord, RecordShape } from "./GadgetRecord.js";
19+
import { GadgetRecordList } from "./GadgetRecordList.js";
20+
import { ErrorsSelection, hydrateConnection, hydrateRecord, hydrateRecordArray, hydrationSelection } from "./support.js";
2521
import type {
2622
AnyFilter,
2723
InternalFieldSelection,

packages/api-client-core/src/exchanges/liveQueryExchange.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const liveQueryExchange: Exchange = ({ forward }) => {
1717
return (operations$) => {
1818
const notLive = pipe(
1919
operations$,
20-
filter((op) => !op.query.definitions.some(isLiveQueryOperationDefinitionNode))
20+
filter((op) => "definitions" in op.query && !op.query.definitions.some(isLiveQueryOperationDefinitionNode))
2121
);
2222

2323
const live = pipe(
2424
operations$,
25-
filter((op) => op.query.definitions.some(isLiveQueryOperationDefinitionNode)),
25+
filter((op) => "definitions" in op.query && op.query.definitions.some(isLiveQueryOperationDefinitionNode)),
2626
filter((op) => {
2727
const opId = getOperationId(op);
2828
return !executed.has(opId) || op.kind !== "query";

packages/api-client-core/src/exchanges/operationNameExchange.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ const graphqlDocumentName = (doc: DocumentNode) => {
1717

1818
export const operationNameExchange: Exchange = mapExchange({
1919
onOperation: (operation) => {
20-
operation.context.operationName ??= graphqlDocumentName(operation.query) || "unknown";
20+
if (operation.context.operationName) {
21+
return;
22+
}
23+
24+
const operationName = "definitions" in operation.query && graphqlDocumentName(operation.query);
25+
26+
operation.context.operationName = operationName || "unknown";
2127
},
2228
});

packages/api-client-core/src/operationBuilders.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1+
import { camelize, capitalizeIdentifier, filterTypeName, namespacify, sortTypeName } from "@gadgetinc/utils";
12
import type { FieldSelection as BuilderFieldSelection, BuilderOperation, Variable } from "tiny-graphql-query-compiler";
23
import { Call, Var, compileWithVariableValues } from "tiny-graphql-query-compiler";
34
import type { FieldSelection } from "./FieldSelection.js";
45
import type { AnyActionFunction, HasReturnType } from "./index.js";
5-
import {
6-
ErrorsSelection,
7-
camelize,
8-
capitalizeIdentifier,
9-
filterTypeName,
10-
hydrationSelection,
11-
namespacify,
12-
sortTypeName,
13-
} from "./support.js";
6+
import { ErrorsSelection, hydrationSelection } from "./support.js";
147
import type { ActionFunctionOptions, BaseFindOptions, EnqueueBackgroundActionOptions, FindManyOptions, VariablesOptions } from "./types.js";
158

169
/**

0 commit comments

Comments
 (0)