Skip to content

Commit

Permalink
Merge pull request #320 from psteinroe/fix/normalize-response
Browse files Browse the repository at this point in the history
fix: normalize response for subscription query
  • Loading branch information
psteinroe authored Nov 7, 2023
2 parents f2d5ef9 + 92936c6 commit 7d9e27e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-fans-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@supabase-cache-helpers/postgrest-core": patch
---

chore: export normalizeResponse function
6 changes: 6 additions & 0 deletions .changeset/thin-pigs-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@supabase-cache-helpers/postgrest-react-query": patch
"@supabase-cache-helpers/postgrest-swr": patch
---

fix: normalize response of useSubscriptionQuery
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
max_attempts: 3
timeout_minutes: 5
retry_on: error
command: supabase start
command: supabase start -x edge-runtime,logflare,vector,studio,imgproxy,pgadmin-schema-diff,migra,postgres-meta --ignore-health-check

- name: 🦺 Check Format and Lint
id: static
Expand Down
2 changes: 1 addition & 1 deletion packages/postgrest-core/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import * as Import from '../src';

describe('index exports', () => {
it('should export', () => {
expect(Object.keys(Import)).toHaveLength(35);
expect(Object.keys(Import)).toHaveLength(36);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const buildMutationFetcherResponse = <R>(
/**
* Normalize the response by removing the dedupe alias and flattening it
**/
const normalizeResponse = <R>(paths: Path[], obj: R): R => {
export const normalizeResponse = <R>(paths: Path[], obj: R): R => {
const groups = groupPathsRecursive(paths);

return groups.reduce<R>((prev, curr) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@supabase/supabase-js';
import {
buildNormalizedQuery,
normalizeResponse,
RevalidateOpts,
} from '@supabase-cache-helpers/postgrest-core';
import { MutationOptions as ReactQueryMutatorOptions } from '@tanstack/react-query';
Expand Down Expand Up @@ -118,7 +119,9 @@ function useSubscriptionQuery<
qb.eq(pk.toString(), data[pk]);
}
const res = await qb.single();
if (res.data) data = res.data as R;
if (res.data) {
data = normalizeResponse(selectQuery.paths, res.data) as R;
}
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@supabase/supabase-js';
import {
buildNormalizedQuery,
normalizeResponse,
RevalidateOpts,
} from '@supabase-cache-helpers/postgrest-core';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -118,7 +119,9 @@ function useSubscriptionQuery<
qb.eq(pk.toString(), data[pk]);
}
const res = await qb.single();
if (res.data) data = res.data as R;
if (res.data) {
data = normalizeResponse(selectQuery.paths, res.data) as R;
}
}

if (
Expand Down

1 comment on commit 7d9e27e

@vercel
Copy link

@vercel vercel bot commented on 7d9e27e Nov 7, 2023

Choose a reason for hiding this comment

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

Deployment failed with the following error:

Resource is limited - try again in 44 minutes (more than 100, code: "api-deployments-free-per-day").

Please sign in to comment.