Skip to content

Commit

Permalink
fix: Fix passing to connectQuery.target query with initialData (#378)
Browse files Browse the repository at this point in the history
* fix: Fix passing to connectQuery.target query with initialData

* test: add tests for issue 377

* lint: format

* Allow passing to connectQuery query with initialData
  • Loading branch information
NazariiShvets committed Oct 11, 2023
1 parent 0b007cf commit 8590dfb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-bees-smile.md
@@ -0,0 +1,5 @@
---
'@farfetched/core': patch
---

Allow passing to connectQuery query with initialData
21 changes: 20 additions & 1 deletion packages/core/src/query/__tests__/connect_query.test-d.ts
@@ -1,4 +1,4 @@
import { createStore, Store, attach, Effect } from 'effector';
import { createStore, Store, attach, Effect, createEffect } from 'effector';
import { describe, test, expectTypeOf } from 'vitest';

import { createQuery } from '../create_query';
Expand Down Expand Up @@ -190,4 +190,23 @@ describe('connectQuery', () => {
target: someTargetQuery,
});
});

test('can use query with initialData', () => {
type Query1Data = { foo: string };
type Query2Data = { bar: string };

const query1 = createQuery({
effect: createEffect((): Query1Data => ({ foo: 'foo' })),
});

const query2 = createQuery({
initialData: { bar: '42' } as Query2Data,
effect: createEffect((): Query2Data => ({ bar: 'bar' })),
});

connectQuery({
source: query1,
target: query2,
});
});
});
4 changes: 2 additions & 2 deletions packages/core/src/query/connect_query.ts
Expand Up @@ -12,11 +12,11 @@ type NonExtendable = {
[K in string]: never;
};

export function connectQuery<Sources, Target extends Query<any, any, any>>(
export function connectQuery<Sources, Target extends Query<any, any, any, any>>(
args: {
source: Sources;
target: Target | [...Target[]];
} & (Target extends Query<infer P, any, any>
} & (Target extends Query<infer P, any, any, any>
? P extends void
? { fn?: undefined }
: Sources extends Query<any, any, any>
Expand Down

0 comments on commit 8590dfb

Please sign in to comment.