Skip to content

Commit

Permalink
Update Boxed & Request
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodyowl committed Apr 22, 2024
1 parent 74f4461 commit dadbc54
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 29 deletions.
4 changes: 1 addition & 3 deletions example/components/FilmList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ export const FilmList = ({
<Film
film={node}
key={node.id}
isActive={activeFilm
.map((id) => node.id === id)
.getWithDefault(false)}
isActive={activeFilm.map((id) => node.id === id).getOr(false)}
onPress={onPressFilm}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
},
"dependencies": {
"@0no-co/graphql.web": "^1.0.6",
"@swan-io/boxed": "^2.1.1",
"@swan-io/request": "^1.0.4",
"@swan-io/boxed": "^2.2.1",
"@swan-io/request": "^1.0.5",
"ts-pattern": "^5.1.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ClientCache {
const serializedVariables = serializeVariables(variables);
const documentCache = Option.fromNullable(
this.operationCache.get(documentNode),
).getWithDefault(new Map());
).getOr(new Map());
documentCache.set(serializedVariables, Option.Some(data));
this.operationCache.set(documentNode, documentCache);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cache/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export const readOperationFromCache = (
previous
.flatMap((previous) => previous.toOption())
.map((previous) => deepEqual(value, previous))
.getWithDefault(false)
.getOr(false)
) {
return previous;
} else {
Expand Down
10 changes: 3 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const defaultMakeRequest: MakeRequest = ({
method: "POST",
responseType: "json",
headers,
withCredentials: Option.fromNullable(withCredentials).getWithDefault(false),
withCredentials: Option.fromNullable(withCredentials).getOr(false),
body: JSON.stringify({
operationName,
query: print(document),
Expand Down Expand Up @@ -185,9 +185,7 @@ export class Client {
this.getTransformedDocumentsForRequest(document);

const operationName =
getExecutableOperationName(transformedDocument).getWithDefault(
"Untitled",
);
getExecutableOperationName(transformedDocument).getOr("Untitled");

const variablesAsRecord = variables as Record<string, unknown>;

Expand All @@ -211,9 +209,7 @@ export class Client {
return this.makeRequest({
url: this.url,
operationName,
document: possiblyOptimizedQuery.getWithDefault(
transformedDocumentsForRequest,
),
document: possiblyOptimizedQuery.getOr(transformedDocumentsForRequest),
variables: variablesAsRecord,
...overrides,
headers: {
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export const addIdIfPreviousSelected = (
...newSelectionSet.selections,
] as readonly SelectionNode[],
}))
.getWithDefault(newSelectionSet);
.getOr(newSelectionSet);
};

export const isExcluded = (
Expand Down
2 changes: 1 addition & 1 deletion src/react/useDeferredQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useDeferredQuery = <Data, Variables>(
const asyncData = useMemo(() => {
return data
.map((value) => AsyncData.Done(value as Result<Data, ClientError>))
.getWithDefault(AsyncData.NotAsked());
.getOr(AsyncData.NotAsked());
}, [data]);

const runQuery = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion src/react/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const useQuery = <Data, Variables>(
const asyncData = useMemo(() => {
return data
.map((value) => AsyncData.Done(value as Result<Data, ClientError>))
.getWithDefault(AsyncData.Loading());
.getOr(AsyncData.Loading());
}, [data]);

const previousAsyncData = usePreviousValue(asyncData);
Expand Down
6 changes: 4 additions & 2 deletions test/__snapshots__/cache.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,9 @@ Map {
`;
exports[`Write & read in cache 7`] = `
t {
{
"tag": "Some",
"value": t {
"value": {
"tag": "Ok",
"value": {
"__typename": "Query",
Expand Down Expand Up @@ -818,6 +818,8 @@ t {
],
},
},
Symbol(__boxed_type__): "Result",
},
Symbol(__boxed_type__): "Option",
}
`;
4 changes: 2 additions & 2 deletions test/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ test("Write & read in cache", () => {
expect(
optimizeQuery(cache, preparedOtherAppQuery, { id: "1" })
.map(print)
.getWithDefault("no delta"),
.getOr("no delta"),
).toMatchSnapshot();

expect(
optimizeQuery(cache, preparedAppQueryWithExtraArrayInfo, { id: "1" })
.map(print)
.getWithDefault("no delta"),
.getOr("no delta"),
).toMatchSnapshot();

const cache2 = new ClientCache({ interfaceToTypes: {} });
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1444,15 +1444,15 @@
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e"
integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==

"@swan-io/boxed@^2.1.1":
version "2.1.1"
resolved "https://registry.yarnpkg.com/@swan-io/boxed/-/boxed-2.1.1.tgz#bdf17d725270c8560d2371972427b6f7e80da5d8"
integrity sha512-NzmIVAnJuzuPwm8ZR4I9tUpuo9qjtVNA7aTSZYdSvcJ+y7NTyt9+tCi4y87T3m8hACN2ATMqvTmRtHOSDIIz7w==
"@swan-io/boxed@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@swan-io/boxed/-/boxed-2.2.1.tgz#adda3c08bad0215a90cfced371817484ef90ad50"
integrity sha512-jJiiVd9CzVPQUb8OuFeGddruTkbLBNCiL2RvN8Jt+Eul7EMkXB/gY4dUYffxyLMDnn2t3EaZahYQ+yHvtLxzDg==

"@swan-io/request@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@swan-io/request/-/request-1.0.4.tgz#9578892306b92c335b064051e165a55268817d14"
integrity sha512-3KguAxPCJ0EBlETij2volJw68k4lOw4nxjw1SkjStyjA50awFxx5UwgUeGfocsDbI7EwPqs1oH3E23hoAcni5w==
"@swan-io/request@^1.0.5":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@swan-io/request/-/request-1.0.5.tgz#3e4fd8e0d699bde18fa7338939c4f2de92ab7dae"
integrity sha512-inXD6hBUmbbDyzAAL30yEaIuSmTCjzyGpQwejdTTDE63qNnDpOVj4SZzsMgph8q1xCq5r3tLm5QgvN2HGuneIw==

"@types/estree@1.0.5", "@types/estree@^1.0.0":
version "1.0.5"
Expand Down

0 comments on commit dadbc54

Please sign in to comment.