Skip to content

Feat/compt 40 create query factory#3

Merged
a-elkhiraooui-ciscode merged 4 commits intodevelopfrom
feat/COMPT-40-create-query-factory
Apr 6, 2026
Merged

Feat/compt 40 create query factory#3
a-elkhiraooui-ciscode merged 4 commits intodevelopfrom
feat/COMPT-40-create-query-factory

Conversation

@a-elkhiraooui-ciscode
Copy link
Copy Markdown

Summary

  • What does this PR change?

Why

  • Why is this change needed?

Checklist

  • Added/updated tests (if behavior changed)
  • npm run lint passes
  • npm run typecheck passes
  • npm test passes
  • npm run build passes
  • Added a changeset (npx changeset) if this affects consumers

Notes

  • Anything reviewers should pay attention to?

- Add createQuery(keyFn, fetcher) returning QueryDefinition<TParams, TData>
- TData and TParams fully inferred from fetcher signature, zero manual annotation
- queryKey returns stable readonly tuple via keyFn
- useQuery shorthand hook wraps useTanstackQuery with typed params
- Export from src/index.ts
- Add @tanstack/react-query as peerDependency (>=5) and devDependency
- Add pnpm cssstyle override to fix Node.js v22 + jsdom@28 ESM compat issue
- Fix duplicate import in vitest.config.ts
- 9 tests, 100% coverage on createQuery.ts, 88.6% overall

Closes COMPT-40
@a-elkhiraooui-ciscode a-elkhiraooui-ciscode requested a review from a team as a code owner April 6, 2026 10:57
Copilot AI review requested due to automatic review settings April 6, 2026 10:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a small “query factory” abstraction over TanStack React Query v5 and exposes it through the library’s public API (src/index.ts), along with adding the needed dependency metadata.

Changes:

  • Added createQuery factory that returns { queryKey, queryFn, useQuery } for a given key function + fetcher.
  • Added a Vitest test suite for createQuery.
  • Exported the new query module from the package entrypoint and added @tanstack/react-query as a peer/dev dependency (plus an npm override).

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vitest.config.ts Removes a duplicate import.
src/query/index.ts Adds a barrel export for the query module.
src/query/createQuery.ts Implements the createQuery factory and types.
src/query/createQuery.test.tsx Adds unit/integration tests for the factory and hook behavior.
src/index.ts Exposes the query module in the public API.
package.json Adds react-query peer/dev dependency and a cssstyle override.
package-lock.json Updates lockfile to reflect dependency/override changes.

Comment on lines +37 to +46
it('queryKey produces a stable reference for the same params', () => {
const def = createQuery(
(id: number) => ['item', id] as const,
async (id: number) => id,
);

const first = def.queryKey(1);
const second = def.queryKey(1);
expect(first).toEqual(second);
});
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The test name claims the query key reference is stable for the same params, but the assertion only checks deep equality (toEqual). Also, keyFn as written returns a new array each call, so a true referential-stability assertion (toBe) would fail. Consider either updating the assertion/test to reflect referential stability (and implementing memoization), or renaming the test to only assert structural equality.

Copilot uses AI. Check for mistakes.
queryKey: keyFn,
queryFn: fetcher,
useQuery(params, options) {

Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

There is stray whitespace on the blank line inside useQuery (will typically fail Prettier/ESLint no-trailing-spaces rules). Remove the extra spaces so formatting stays clean.

Suggested change

Copilot uses AI. Check for mistakes.
@a-elkhiraooui-ciscode a-elkhiraooui-ciscode merged commit b253ea6 into develop Apr 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants