Skip to content

feat: rewrite to ember-resources#4

Draft
johanrd wants to merge 1 commit intov4from
ember-resources/rewrite
Draft

feat: rewrite to ember-resources#4
johanrd wants to merge 1 commit intov4from
ember-resources/rewrite

Conversation

@johanrd
Copy link
Owner

@johanrd johanrd commented Feb 10, 2026

Rewrite internals to use ember-resources

Replaces the custom Resource base class and useResource helper with https://github.com/NullVoxPopuli/ember-resources primitives (resource, resourceFactory, @use).

What changed

  • Removed resource.ts and use-resource.ts — the custom resource lifecycle framework
  • Rewrote query.ts, mutation.ts, subscription.ts to use resource() from ember-resources with a Proxy wrapper for reactive cache invalidation
  • Simplified usables.ts — useQuery/useMutation/useSubscription now delegate directly to the resource factories
  • New primary API: queryResource, mutationResource, subscriptionResource — work with @use decorator and in templates via resourceFactory
  • Added createQueryResource, createMutationResource, createSubscriptionResource — curried factories that bake in the document for define-once-reuse-everywhere patterns
  • Updated docs, README, and UPGRADE.md

New curried factory API

  const userInfo = createQueryResource<UserInfoQuery, UserInfoQueryVariables>(USER_INFO);

  // Class usage
  @use query = userInfo(() => ({ variables: { id: this.args.userId } }));

  // Template usage
  {{#let (userInfo (hash variables=(hash id="1"))) as |q|}} ... {{/let}}

Backward compatible

useQuery, useMutation, and useSubscription continue to work unchanged.

Cowritten by claude

Copy link

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 rewrites Glimmer Apollo’s internal resource implementation to use ember-resources primitives, introducing first-class resource factories for @use/template usage while keeping useQuery/useMutation/useSubscription as convenience wrappers.

Changes:

  • Replaced the custom resource lifecycle implementation with ember-resources (resource, resourceFactory, @use, use).
  • Introduced/standardized the new primary APIs: queryResource, mutationResource, subscriptionResource plus create*Resource curried variants.
  • Updated tests and documentation to cover and recommend the new factory-based usage patterns.

Reviewed changes

Copilot reviewed 21 out of 23 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test-app/tests/unit/query-test.ts Adds coverage for Apollo Client 4 refetch behavior on skipped/standby queries.
test-app/tests/unit/custom-query-test.ts Updates “custom query” composition to use the new queryResource factory + use.
test-app/tests/integration/components/resource-factory-test.gts New integration tests validating @use, template invocation via resourceFactory, and curried factories.
test-app/package.json Adds ember-resources to the test app dependencies.
test-app/app/components/experiment.gts Migrates demo component usage from useQuery/useMutation to @use + resource factories.
pnpm-lock.yaml Locks ember-resources dependency additions.
glimmer-apollo/src/index.ts Exposes resource factories as the primary API and keeps use* wrappers as convenience exports.
glimmer-apollo/src/environment.ts Removes exports only needed by the old custom Resource/helper-manager implementation.
glimmer-apollo/src/-private/use-resource.ts Deletes the old useResource/helper-manager based implementation.
glimmer-apollo/src/-private/usables.ts Reimplements useQuery/useMutation/useSubscription wrappers using ember-resources use(...).
glimmer-apollo/src/-private/types.ts Removes types tied to the deleted custom resource framework.
glimmer-apollo/src/-private/subscription.ts Rewrites subscriptions to ember-resources + proxy invalidation; adds curried factory.
glimmer-apollo/src/-private/resource.ts Deletes the custom Resource base class and helper manager.
glimmer-apollo/src/-private/query.ts Rewrites queries to ember-resources + proxy invalidation; adds curried factory.
glimmer-apollo/src/-private/observable.ts Refactors observable helper base to no longer depend on the removed Resource base class.
glimmer-apollo/src/-private/mutation.ts Rewrites mutations to ember-resources; adds curried factory.
glimmer-apollo/package.json Adds ember-resources as dev + peer dependency for the addon package.
docs/fetching/subscriptions.md Updates docs to recommend subscriptionResource + @use and keeps useSubscription as alternative.
docs/fetching/queries.md Updates docs to recommend queryResource + @use and keeps useQuery as alternative.
docs/fetching/mutations.md Updates docs to recommend mutationResource + @use and keeps useMutation as alternative.
UPGRADE.md Documents the new factory APIs, curried factories, and removed helper type exports.
README.md Updates README examples to the new recommended @use + resource factory API.
.claude/settings.local.json Adds an empty local settings file.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)

glimmer-apollo/src/-private/subscription.ts:70

  • In FastBoot, _start returns early when options.ssr === false but leaves loading set to true (and promise unset). That can leave consumers stuck in a perpetual "connecting" state during SSR. Consider setting loading=false and promise=Promise.resolve() (and ensuring hasActiveSubscription remains false) before returning.
    this.loading = true;
    const fastboot = getFastboot(this);

    if (fastboot && fastboot.isFastBoot && options && options.ssr === false) {
      return;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 122 to 124
import {
ON_MESSAGED_ADDED,
OnMessageAddedSubscription,
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The identifier ON_MESSAGED_ADDED in this example looks like a typo (extra “D”). Renaming it to ON_MESSAGE_ADDED would avoid confusion for readers copying the snippet.

Copilot uses AI. Check for mistakes.
@johanrd johanrd force-pushed the ember-resources/rewrite branch from dee5b9d to 971196e Compare February 10, 2026 22:14
@johanrd johanrd force-pushed the ember-resources/rewrite branch from 971196e to 4dbacf7 Compare February 10, 2026 22:19
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