A powerful integration of Effect with TanStack Query for SolidJS applications, bringing functional programming patterns and type-safe error handling to your data fetching layer.
This monorepo contains three packages that work together to provide a complete Effect + TanStack Query solution for SolidJS:
| Package | Description | Version |
|---|---|---|
| solid-effect-query | Core Effect integration with TanStack Query | 0.1.0 |
| solid-effect-query-http-api | Effect Platform HTTP API integration | 0.1.0 |
| solid-effect-query-rpc | Effect RPC client integration | 0.1.0 |
# Core package
npm install solid-effect-query @tanstack/solid-query effect
# For HTTP API support
npm install solid-effect-query-http-api @effect/platform
# For RPC support
npm install solid-effect-query-rpc @effect/rpc @effect/rpc-httpimport { makeEffectRuntime } from "solid-effect-query";
import { Effect, Layer } from "effect";
import { createSignal, Show } from "solid-js";
// Create a runtime with your services
const { Provider, useEffectQuery, useEffectMutation } = makeEffectRuntime(() =>
Layer.empty // Add your services here
);
function App() {
return (
<Provider>
<TodoList />
</Provider>
);
}
function TodoList() {
const query = useEffectQuery(() => ({
queryKey: ["todos"],
queryFn: () =>
Effect.gen(function* () {
const response = yield* Effect.tryPromise({
try: () => fetch("/api/todos").then(r => r.json()),
catch: (error) => new Error(`Failed to fetch: ${error}`)
});
return response;
})
}));
return (
<div>
<Show when={query.isPending}>
<div>Loading...</div>
</Show>
<Show when={query.isError}>
<div>Error: {query.error?.message}</div>
</Show>
<Show when={query.isSuccess}>
<ul>
{query.data.map(todo => (
<li>{todo.title}</li>
))}
</ul>
</Show>
</div>
);
}- π― Type-safe error handling - Leverage Effect's powerful error management system
- π Runtime management - Manage Effect services and dependencies with SolidJS context
- π HTTP API integration - Type-safe API clients with schema validation
- π‘ RPC support - Seamless client-server communication with automatic batching
- πͺ Full TanStack Query features - Caching, mutations, optimistic updates, infinite queries, and more
- π Compile-time safety - Catch errors at build time, not runtime
- β‘ SolidJS reactive - Built specifically for SolidJS's fine-grained reactivity
import { Context, Layer, Effect } from "effect";
import { makeEffectRuntime } from "solid-effect-query";
// Define a service
class LoggerService extends Context.Tag("Logger")<
LoggerService,
{ log: (message: string) => Effect.Effect<void> }
>() {}
// Create layer
const LoggerLive = Layer.succeed(
LoggerService,
{ log: (message) => Effect.log(message) }
);
// Create runtime with the service
const { Provider, useEffectQuery } = makeEffectRuntime(() => LoggerLive);
function DataComponent() {
const query = useEffectQuery(() => ({
queryKey: ["data-with-logging"],
queryFn: () =>
Effect.gen(function* () {
const logger = yield* LoggerService;
yield* logger.log("Fetching data...");
const data = yield* fetchData();
yield* logger.log("Data fetched successfully");
return data;
})
}));
return <div>{/* render data */}</div>;
}import { makeHttpApiQuery } from "solid-effect-query-http-api";
import { Schema } from "effect";
import * as HttpApi from "@effect/platform/HttpApi";
// Define your API schema
class TodosApi extends HttpApi.make("todos").pipe(
HttpApi.add(
HttpApi.get("list", "/todos").pipe(
HttpApi.setSuccess(Schema.Array(TodoSchema))
)
)
) {}
// Use in component
function TodoList() {
const query = makeHttpApiQuery(
TodosApi,
runtime,
"list",
() => ({ queryKey: ["todos"] })
);
return <div>{/* render todos */}</div>;
}This project uses pnpm workspaces for managing the monorepo.
# Clone the repository
git clone https://github.com/Frank-III/solid-effect-query.git
cd solid-effect-query
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run the demo application
pnpm dev --filter=demo-app
# Run tests
pnpm test
# Type checking
pnpm typecheck
# Linting
pnpm lintsolid-effect-query/
βββ packages/
β βββ solid-effect-query/ # Core package
β βββ solid-effect-query-http-api/ # HTTP API integration
β βββ solid-effect-query-rpc/ # RPC integration
βββ examples/
β βββ demo-app/ # Demo application
βββ docs/ # Documentation
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to:
- Update tests as appropriate
- Update documentation
- Follow the existing code style
- Add changeset for version management
MIT Β© Frank Wang
- Effect - The standard library for TypeScript
- TanStack Query - Powerful asynchronous state management
- SolidJS - A declarative, efficient, and flexible JavaScript library
- effect-react-query - Inspiration for this SolidJS version