Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
251 commits
Select commit Hold shift + click to select a range
d0c974f
Remove updateresults call
Sep 8, 2022
1aa75bf
add test support and query client provider tests
lukesmurray Sep 8, 2022
c541037
Merge pull request #1 from lukesmurray/luke/test-support
Sep 8, 2022
8bf5b6f
add exports to match react query exports
lukesmurray Sep 8, 2022
e611eab
Merge pull request #2 from lukesmurray/luke/match-react-query-exports
lukesmurray Sep 8, 2022
1e39918
reformat with prettier
lukesmurray Sep 8, 2022
c65e561
Merge pull request #3 from ardeora/luke/reformat
lukesmurray Sep 8, 2022
e7c8759
fix lint and typecheck errors
lukesmurray Sep 8, 2022
3cf1a54
Merge pull request #4 from lukesmurray/luke/fix-linting
lukesmurray Sep 8, 2022
77cbabf
fix npm run build
lukesmurray Sep 9, 2022
e86a44a
fix babel config
lukesmurray Sep 9, 2022
dca3c5d
Merge pull request #5 from lukesmurray/luke/fix-build
lukesmurray Sep 9, 2022
0a18d58
Completely reactive useIsFetching with correct queryKey types
Sep 9, 2022
712966c
fix build types.
lukesmurray Sep 9, 2022
716c089
Merge pull request #6 from ardeora/luke/fix-build-types
lukesmurray Sep 9, 2022
62f2871
add the first solid example
lukesmurray Sep 9, 2022
2b94358
Merge pull request #7 from ardeora/luke/solid-basic-example
lukesmurray Sep 9, 2022
2afd447
fix query types
lukesmurray Sep 9, 2022
73be3fb
rename useQuery test to createQuery
lukesmurray Sep 9, 2022
cce4791
Merge pull request #8 from ardeora/luke/query-types
lukesmurray Sep 9, 2022
f01de0f
get eslint to pass.
lukesmurray Sep 9, 2022
f363c08
remove unused codemods test
lukesmurray Sep 9, 2022
5f3580f
Merge pull request #9 from ardeora/luke/pass-linting
lukesmurray Sep 9, 2022
5d7fc34
add createQuery test
lukesmurray Sep 9, 2022
c8f7dda
fix type tests and add comments to errors
lukesmurray Sep 9, 2022
9dc8635
fix comment in types
lukesmurray Sep 9, 2022
566bb61
Keep comments and better organization of types by functions
Sep 9, 2022
333eb04
Merge pull request #10 from ardeora/adeora/comments-cleanup
Sep 9, 2022
c048a75
Fix: Typo in useIsFetching
Sep 9, 2022
489426b
Merge pull request #11 from ardeora/adeora/comments-cleanup
Sep 9, 2022
4ac03a5
update test utils
lukesmurray Sep 9, 2022
990bfa4
shoudl allow to set default data value passing
lukesmurray Sep 9, 2022
23d72a1
change createBaseQuery to use mutate instead of refetch
lukesmurray Sep 9, 2022
4a2e236
correct state for successful query working
lukesmurray Sep 9, 2022
aadb48f
correct states for incorrect query passing
lukesmurray Sep 9, 2022
3f160df
translate set isFetchedAfterMount
lukesmurray Sep 9, 2022
5ac2c11
partial conversion of createQuery tests to solid
lukesmurray Sep 9, 2022
4e2a6ca
replace remaining instances of renderWithClient
lukesmurray Sep 9, 2022
fe69166
replace useQuery with createQuery
lukesmurray Sep 9, 2022
b5528a2
add comment about excluding tests in tsconfig.json
lukesmurray Sep 9, 2022
9891e87
translate some more tests in createQuery
lukesmurray Sep 9, 2022
d32beb8
revert mutate change
lukesmurray Sep 9, 2022
0fbe6ea
add simple example but in typescript
lukesmurray Sep 9, 2022
4782017
add examples to package.json
lukesmurray Sep 9, 2022
659bb65
Merge pull request #12 from ardeora/luke/query-tests
Sep 9, 2022
c5745a2
add temporary readme documenting examples progress
lukesmurray Sep 9, 2022
da98b26
add the graphql example
lukesmurray Sep 9, 2022
f0f32d5
add default query function example
lukesmurray Sep 10, 2022
e1b4e85
chore: update package-lock.json
jennyckaplan Sep 10, 2022
cf804a1
Fix eslint config to make it stop complaining
Sep 10, 2022
50f652d
Add createInfiniteQuery
Sep 10, 2022
496147b
Merge pull request #16 from ardeora/adeora/createInfiniteQuery
Sep 10, 2022
239efbc
Merge pull request #14 from jennyckaplan/jck/update-package-json
Sep 10, 2022
2238d82
fix: jest tests, copy over React query index file
jennyckaplan Sep 11, 2022
1652073
fix: resolve data field to value of state when not loading, otherwise…
jennyckaplan Sep 11, 2022
b479cba
add is fetching and is mutating tests
lukesmurray Sep 10, 2022
3fb1beb
update provider to use context sharing
lukesmurray Sep 11, 2022
06459d5
add error reset boundary
lukesmurray Sep 11, 2022
05bd8b3
update package exports
lukesmurray Sep 11, 2022
14d7aa1
add reset error boundary tests
lukesmurray Sep 11, 2022
400ed07
add property tracking to query
lukesmurray Sep 11, 2022
88e6d98
get another query test passing
lukesmurray Sep 11, 2022
4b6a264
another test passes
lukesmurray Sep 11, 2022
cd4c935
more tests transpiled
lukesmurray Sep 11, 2022
f57f7cf
fix custom context in create base query
lukesmurray Sep 11, 2022
587ef2e
update query error reset boundary tests
lukesmurray Sep 11, 2022
806942a
most error reset boundary test cases passing
lukesmurray Sep 11, 2022
5604855
get a suspense test passing
lukesmurray Sep 11, 2022
8555f14
bunch of suspense cases passing
lukesmurray Sep 12, 2022
e32a6f1
even more suspense tests working
lukesmurray Sep 12, 2022
d0c8b1e
finish migrating suspense tests
lukesmurray Sep 12, 2022
7e8d8b2
add fetching/mutating cases with custom context
lukesmurray Sep 12, 2022
823a51f
add infinite query and mutation tests
lukesmurray Sep 12, 2022
8995090
do not update observer options on mount
lukesmurray Sep 12, 2022
a8a555c
start translating infinite query tests
lukesmurray Sep 12, 2022
ee2fb89
fix: 'setQueryData - should respect updatedAt' test
jennyckaplan Sep 13, 2022
d9c4467
fix: 'should fetch on mount when a query was already created with set…
jennyckaplan Sep 13, 2022
c12a325
fix: 'should refetch after focus regain' test
jennyckaplan Sep 13, 2022
b784663
fix: 'setQueryData - should not call onSuccess callback of active obs…
jennyckaplan Sep 13, 2022
6d115b5
fix: 'online queries should fetch if paused and we go online even if …
jennyckaplan Sep 13, 2022
f8cb5c5
fix: 'online queries should not fetch if paused and we go online if a…
jennyckaplan Sep 13, 2022
70acf67
fix: 'select should always return the correct state' test
jennyckaplan Sep 13, 2022
195b50f
fix: 'should refetch when quickly switching to a failed query' test
jennyckaplan Sep 13, 2022
20656ad
fix: 'online queries should not get stuck in fetching state when paus…
jennyckaplan Sep 13, 2022
39ac3c2
Merge pull request #20 from jennyckaplan/jck/fix-create-base-query-tests
lukesmurray Sep 13, 2022
0e3c21f
fix: 'it should have status=error on mount when a query has failed' test
jennyckaplan Sep 13, 2022
6efedf4
update more create query tests
lukesmurray Sep 13, 2022
830d764
fix: 'should call onSuccess after a query has been refetched' test
jennyckaplan Sep 13, 2022
578f71f
more tests
lukesmurray Sep 13, 2022
f7bfbe0
skip a query error reset boundary test
lukesmurray Sep 14, 2022
95438a5
move state.data matches into switch fallback
lukesmurray Sep 14, 2022
c6d844a
replace show with logical and conditionals
lukesmurray Sep 14, 2022
d7bb5bb
Merge pull request #21 from ardeora/luke/tests-the-sequel
lukesmurray Sep 14, 2022
cc93cb9
fix: skip react specific rendering tests
jennyckaplan Sep 14, 2022
02cae55
fix: 'errorUpdateCount should increased on each fetch failure' test
jennyckaplan Sep 14, 2022
7f167a4
Merge pull request #22 from jennyckaplan/jck/fix-create-base-query-te…
lukesmurray Sep 14, 2022
26038b9
Fix: Create Base Query consistent return value
Sep 11, 2022
bcd6477
Stashing Changes
Sep 13, 2022
436d722
Much Improved createBaseQuery
Sep 13, 2022
15f08a4
More tests added
Sep 13, 2022
a12136a
More Passing tests and completed base queries
Sep 14, 2022
6be776d
Prettifying stuff ✨
Sep 14, 2022
43c6576
More passing tests
Sep 15, 2022
6bfd6c6
fixing merge
lukesmurray Sep 16, 2022
fa5a690
prettier
lukesmurray Sep 16, 2022
fc2cdcb
more merge fixes
lukesmurray Sep 16, 2022
4f3f455
add comment about reactive notifyOnChange props
lukesmurray Sep 16, 2022
4ddfc1a
ignore some errors in tests
lukesmurray Sep 16, 2022
4315958
replace instances of test with it
lukesmurray Sep 16, 2022
9e055e4
replace react in comment with solid
lukesmurray Sep 16, 2022
4ae8b17
Completed tests and reviewed PR
Sep 17, 2022
88df659
Prettifying and removing logs
Sep 17, 2022
2c93031
Merge pull request #26 from ardeora/adeora/luke/use-is-fetching-tests
Sep 17, 2022
41f864e
Merge pull request #17 from ardeora/luke/use-is-fetching-tests
Sep 17, 2022
68ee982
Small Types Fix for CreateInfiniteQuery
Sep 17, 2022
8ab020d
most infinite query tests passing
lukesmurray Sep 18, 2022
acaf46e
all infinite query tests passing
lukesmurray Sep 18, 2022
5a2e0b9
almost all create mutation tests passing
lukesmurray Sep 18, 2022
0be0786
format with prettier
lukesmurray Sep 18, 2022
ef26e9f
format with prettier
lukesmurray Sep 18, 2022
3ff6926
Added createQueries
Sep 18, 2022
324ebcf
Prettier fix for infiniteQueries
Sep 18, 2022
ead2383
run prettier tests
lukesmurray Sep 18, 2022
1d0fd5c
add createQueries tests
lukesmurray Sep 18, 2022
cf431c8
Fix infiniteQueries Formatting
Sep 19, 2022
528b643
Merge pull request #30 from ardeora/luke/create-queries-tests
Sep 19, 2022
e1c3cb4
Making options reactive + added batching tasks
Sep 19, 2022
88f5e26
Merge branch 'adeora/createQueries' of https://github.com/ardeora/que…
Sep 19, 2022
eeb425f
Merge pull request #29 from ardeora/adeora/createQueries
Sep 19, 2022
76eea56
Merge pull request #28 from ardeora/luke/create-mutation
Sep 19, 2022
4175685
Merge pull request #27 from ardeora/luke/use-infinite-query
Sep 19, 2022
c6fe06c
Throw to errorBoundary when options set correctly
Sep 19, 2022
2a2c7ef
WIP: Added solid query primitives
Sep 8, 2022
f299d22
Remove updateresults call
Sep 8, 2022
39308c9
add test support and query client provider tests
lukesmurray Sep 8, 2022
62b17bd
add exports to match react query exports
lukesmurray Sep 8, 2022
34b6613
reformat with prettier
lukesmurray Sep 8, 2022
c63f469
fix lint and typecheck errors
lukesmurray Sep 8, 2022
98dc5c3
fix npm run build
lukesmurray Sep 9, 2022
d105fd9
fix babel config
lukesmurray Sep 9, 2022
b549dbd
Completely reactive useIsFetching with correct queryKey types
Sep 9, 2022
f40b053
fix build types.
lukesmurray Sep 9, 2022
51f1e50
add the first solid example
lukesmurray Sep 9, 2022
f6626f9
fix query types
lukesmurray Sep 9, 2022
05a684f
rename useQuery test to createQuery
lukesmurray Sep 9, 2022
46e14de
get eslint to pass.
lukesmurray Sep 9, 2022
66d9acd
remove unused codemods test
lukesmurray Sep 9, 2022
05f0018
Keep comments and better organization of types by functions
Sep 9, 2022
6014532
Fix: Typo in useIsFetching
Sep 9, 2022
9f447af
add createQuery test
lukesmurray Sep 9, 2022
eeff6da
fix type tests and add comments to errors
lukesmurray Sep 9, 2022
b8cc939
fix comment in types
lukesmurray Sep 9, 2022
8217219
update test utils
lukesmurray Sep 9, 2022
b1829a0
shoudl allow to set default data value passing
lukesmurray Sep 9, 2022
8213f1e
change createBaseQuery to use mutate instead of refetch
lukesmurray Sep 9, 2022
ad896c1
correct state for successful query working
lukesmurray Sep 9, 2022
4a02545
correct states for incorrect query passing
lukesmurray Sep 9, 2022
09d46d3
translate set isFetchedAfterMount
lukesmurray Sep 9, 2022
8e3ee88
partial conversion of createQuery tests to solid
lukesmurray Sep 9, 2022
6f1660d
replace remaining instances of renderWithClient
lukesmurray Sep 9, 2022
bd1ad77
replace useQuery with createQuery
lukesmurray Sep 9, 2022
7aadd70
add comment about excluding tests in tsconfig.json
lukesmurray Sep 9, 2022
0ac3993
translate some more tests in createQuery
lukesmurray Sep 9, 2022
ae6e4e2
revert mutate change
lukesmurray Sep 9, 2022
26c248a
Fix eslint config to make it stop complaining
Sep 10, 2022
4b1a410
Add createInfiniteQuery
Sep 10, 2022
ac96f74
chore: update package-lock.json
jennyckaplan Sep 10, 2022
532d21a
fix: jest tests, copy over React query index file
jennyckaplan Sep 11, 2022
21c1195
fix: resolve data field to value of state when not loading, otherwise…
jennyckaplan Sep 11, 2022
55a0700
add is fetching and is mutating tests
lukesmurray Sep 10, 2022
9b45c39
update provider to use context sharing
lukesmurray Sep 11, 2022
212c19a
add error reset boundary
lukesmurray Sep 11, 2022
e9d4dec
update package exports
lukesmurray Sep 11, 2022
b4bbe8f
add reset error boundary tests
lukesmurray Sep 11, 2022
5c70b5c
add property tracking to query
lukesmurray Sep 11, 2022
65a6219
get another query test passing
lukesmurray Sep 11, 2022
f3f6cc5
another test passes
lukesmurray Sep 11, 2022
1f6113b
more tests transpiled
lukesmurray Sep 11, 2022
8a39b93
fix custom context in create base query
lukesmurray Sep 11, 2022
4a3476c
update query error reset boundary tests
lukesmurray Sep 11, 2022
409c60d
most error reset boundary test cases passing
lukesmurray Sep 11, 2022
e238ece
get a suspense test passing
lukesmurray Sep 11, 2022
3c744d3
bunch of suspense cases passing
lukesmurray Sep 12, 2022
a1a32cd
even more suspense tests working
lukesmurray Sep 12, 2022
e58b2a1
finish migrating suspense tests
lukesmurray Sep 12, 2022
2cc8269
add fetching/mutating cases with custom context
lukesmurray Sep 12, 2022
e50cb60
add infinite query and mutation tests
lukesmurray Sep 12, 2022
2d225cf
do not update observer options on mount
lukesmurray Sep 12, 2022
7f02c9c
start translating infinite query tests
lukesmurray Sep 12, 2022
5c960e7
fix: 'setQueryData - should respect updatedAt' test
jennyckaplan Sep 13, 2022
28a0975
fix: 'should fetch on mount when a query was already created with set…
jennyckaplan Sep 13, 2022
626438b
fix: 'should refetch after focus regain' test
jennyckaplan Sep 13, 2022
e18cb72
fix: 'setQueryData - should not call onSuccess callback of active obs…
jennyckaplan Sep 13, 2022
3e9a61b
fix: 'online queries should fetch if paused and we go online even if …
jennyckaplan Sep 13, 2022
7e564ea
fix: 'online queries should not fetch if paused and we go online if a…
jennyckaplan Sep 13, 2022
0989741
fix: 'select should always return the correct state' test
jennyckaplan Sep 13, 2022
15ae9a0
fix: 'should refetch when quickly switching to a failed query' test
jennyckaplan Sep 13, 2022
c03f74f
fix: 'online queries should not get stuck in fetching state when paus…
jennyckaplan Sep 13, 2022
2a2c12e
update more create query tests
lukesmurray Sep 13, 2022
ba6f45a
more tests
lukesmurray Sep 13, 2022
f04c20d
skip a query error reset boundary test
lukesmurray Sep 14, 2022
af10e63
move state.data matches into switch fallback
lukesmurray Sep 14, 2022
01c6d08
replace show with logical and conditionals
lukesmurray Sep 14, 2022
ac95785
fix: 'should call onSuccess after a query has been refetched' test
jennyckaplan Sep 13, 2022
d4dbc96
fix: skip react specific rendering tests
jennyckaplan Sep 14, 2022
9d1e2dc
Fix: Create Base Query consistent return value
Sep 11, 2022
94d0d06
Stashing Changes
Sep 13, 2022
8c2856a
Much Improved createBaseQuery
Sep 13, 2022
78917eb
More tests added
Sep 13, 2022
cacae97
More Passing tests and completed base queries
Sep 14, 2022
6cf5001
Prettifying stuff ✨
Sep 14, 2022
9f7669f
More passing tests
Sep 15, 2022
de5a0ba
fixing merge
lukesmurray Sep 16, 2022
e294c6c
prettier
lukesmurray Sep 16, 2022
bfb422f
more merge fixes
lukesmurray Sep 16, 2022
4c95bcc
add comment about reactive notifyOnChange props
lukesmurray Sep 16, 2022
02598ff
ignore some errors in tests
lukesmurray Sep 16, 2022
1f364e8
replace instances of test with it
lukesmurray Sep 16, 2022
c37da6e
replace react in comment with solid
lukesmurray Sep 16, 2022
31cbee1
Completed tests and reviewed PR
Sep 17, 2022
4ee0793
Prettifying and removing logs
Sep 17, 2022
8bc32f8
Small Types Fix for CreateInfiniteQuery
Sep 17, 2022
5a579e4
Prettier fix for infiniteQueries
Sep 18, 2022
b818813
Added createQueries
Sep 18, 2022
3e41d54
Making options reactive + added batching tasks
Sep 19, 2022
5d1a7c3
add createQueries tests
lukesmurray Sep 18, 2022
ab549c6
almost all create mutation tests passing
lukesmurray Sep 18, 2022
b6336ef
most infinite query tests passing
lukesmurray Sep 18, 2022
00a9ef5
all infinite query tests passing
lukesmurray Sep 18, 2022
79c03b2
format with prettier
lukesmurray Sep 18, 2022
ea7f99c
Throw to errorBoundary when options set correctly
Sep 19, 2022
ceef4ac
fix config file bugs
lukesmurray Sep 19, 2022
ffd2e93
fix linting issues
lukesmurray Sep 19, 2022
a182d68
merge solid-query
lukesmurray Sep 19, 2022
5aedc0e
Merge branch 'solid-query' into luke/fix-ci
lukesmurray Sep 19, 2022
924e4d2
Merge pull request #31 from ardeora/luke/fix-ci
lukesmurray Sep 19, 2022
a5b8e07
add solid query docs
lukesmurray Sep 19, 2022
c510ea9
update docs
lukesmurray Sep 19, 2022
617d54e
Merge pull request #32 from ardeora/luke/docs
lukesmurray Sep 19, 2022
7c284f6
update solid-query version in examples
lukesmurray Sep 19, 2022
da713bc
Merge pull request #13 from ardeora/luke/more-examples
lukesmurray Sep 19, 2022
1cf1791
document lack of SSR support
lukesmurray Sep 19, 2022
dc39c08
fix missing import in suspense tests
lukesmurray Sep 19, 2022
1703769
fix bug where disabled queries triggered suspense
lukesmurray Sep 19, 2022
6293ced
Merge pull request #33 from ardeora/luke/suspense-fixes
Sep 19, 2022
b0a53c5
fix build
lukesmurray Sep 20, 2022
4e1dd28
add exports from solid preset
lukesmurray Sep 20, 2022
a157de7
Merge pull request #34 from ardeora/luke/solid-preset
Sep 20, 2022
47cea89
fix build issues
lukesmurray Sep 20, 2022
4a6586a
Updated adapter docs
Sep 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module.exports = {
},
],
'@babel/preset-typescript',
'@babel/react',
],
plugins: [
cjs && ['@babel/transform-modules-commonjs', { loose }],
Expand All @@ -32,4 +31,14 @@ module.exports = {
},
],
].filter(Boolean),
overrides: [
{
exclude: './packages/solid-query/**',
presets: ['@babel/react'],
},
{
include: './packages/solid-query/**',
presets: ['babel-preset-solid'],
},
],
}
201 changes: 198 additions & 3 deletions docs/adapters/solid-query.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,205 @@
---
title: Solid Query (Coming Soon)
title: Solid Query
---

The `@tanstack/solid-query` package provides a 1st-class API for using TanStack Query with SolidJS.

> ⚠️ This module has not yet been developed. It requires an adapter similar to `react-query` to work. We estimate the amount of code to do this is low-to-moderate, but does require familiarity with the SolidJS framework. If you would like to contribute this adapter, please open a PR!
## Example

The `@tanstack/solid-query` package offers a 1st-class API for using TanStack Query via Solid. However, all of the primitives you receive from this API are core APIs that are shared across all of the TanStack Adapters including the Query Client, query results, query subscriptions, etc.
```tsx
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Switch, Match, For } from 'solid-js'

const queryClient = new QueryClient()

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)

return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
</div>
)
}

function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}

```

## Available Functions

Solid Query offers useful primitives and functions that will make managing server state in SolidJS apps easier.

- `createQuery`
- `createQueries`
- `createInfiniteQueries`
- `createMutation`
- `useIsFetching`
- `useIsMutating`
- `useQueryClient`
- `QueryClient`
- `QueryClientProvider`




## Important Differences between Solid Query & React Query

Solid Query offers an API similar to React Query, but there are some key differences to be mindful of.

- To maintain their reactivity, Query keys need to be wrapped inside a function while using `createQuery`, `createQueries`, `createInfiniteQuery` and `useIsFetching`.

```tsx
// ❌ react version
useQuery(["todos", todo], fetchTodos)

// ✅ solid version
createQuery(() => ["todos", todo()], fetchTodos)
```

- Suspense works for queries out of the box if you access the query data inside a `<Suspense>` boundary.

```tsx
import { For, Suspense } from 'solid-js'

function Example() {
const query = createQuery(() => ['todos'], fetchTodos)
return (
<div>
{/* ✅ Will trigger loading fallback, data accessed in a suspense context. */}
<Suspense fallback={"Loading..."}>
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</Suspense>
{/* ❌ Will not trigger loading fallback, data not accessed in a suspense context. */}
<For each={query.data}>{(todo) => <div>{todo.title}</div>}</For>
</div>
)
}
```

- Solid Query primitives (`createX`) do not support destructuring. The return value from these functions is a store, and their properties are only tracked in a reactive context.

```tsx
import { QueryClient, QueryClientProvider, createQuery } from '@tanstack/solid-query'
import { Match, Switch } from 'solid-js'

const queryClient = new QueryClient()

export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}

function Example() {
// ❌ react version -- supports destructing outside reactive context
// const { isLoading, error, data } = useQuery(['repoData'], () =>
// fetch('https://api.github.com/repos/tannerlinsley/react-query').then(res =>
// res.json()
// )
// )

// ✅ solid version -- does not support destructuring outside reactive context
const query = createQuery(
() => ['repoData'],
() =>
fetch('https://api.github.com/repos/tannerlinsley/react-query').then(
(res) => res.json(),
),
)

// ✅ access query properties in JSX reactive context
return (
<Switch>
<Match when={query.isLoading}>Loading...</Match>
<Match when={query.isError}>Error: {query.error.message}</Match>
<Match when={query.isSuccess}>
<div>
<h1>{query.data.name}</h1>
<p>{query.data.description}</p>
<strong>👀 {query.data.subscribers_count}</strong>{' '}
<strong>✨ {query.data.stargazers_count}</strong>{' '}
<strong>🍴 {query.data.forks_count}</strong>
</div>
</Match>
</Switch>
)
}
```

- If you want options to be reactive you need to pass them using object getter syntax. This may look strange at first but it leads to more idiomatic solid code.

```tsx
import {
QueryClient,
QueryClientProvider,
createQuery,
} from '@tanstack/solid-query'
import { createSignal, For } from 'solid-js'

const queryClient = new QueryClient()

function Example() {
const [enabled, setEnabled] = createSignal(false)
const query = createQuery(() => ['todos'], fetchTodos, {
// ❌ passing a signal directly is not reactive
// enabled: enabled(),

// ✅ passing a function that returns a signal is reactive
get enabled() {
return enabled()
},
})

return (
<div>
<Switch>
<Match when={query.isLoading}>
<p>Loading...</p>
</Match>
<Match when={query.isError}>
<p>Error: {query.error.message}</p>
</Match>
<Match when={query.isSuccess}>
<For each={query.data}>
{(todo) => <p>{todo.title}</p>}
</For>
</Match>
</Switch>
<button onClick={() => setEnabled(!enabled())}>Toggle enabled</button>
</div>
)
}

function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
```

- Errors can be caught and reset using SolidJS' native `ErrorBoundary` component. `QueryErrorResetBoundary` is not needed with Solid Query

- Since Property tracking is handled through Solid's fine grained reactivity, options like `notifyOnChangeProps` are not needed
22 changes: 22 additions & 0 deletions examples/solid/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Examples to Add

- auto-refetching 🚫 nextjs (react only)
- basic 🚫 javascript (only converting typescript)
- basic-graphql-request 🟢
- basic-typescript 🟢
- custom-hooks 🚫 not implemented in react
- default-query-function 🟡 (green styling for cached post not working)
- focus-refetching 🚫 not implemented in react
- load-more-infinite-scroll 🚫 nextjs (react only)
- nextjs 🚫 nextjs (react only)
- offline 🔴
- optimistic-updates 🚫 not implemented in react
- optimistic-updates-typescript 🚫 nextjs (react only)
- pagination 🚫 nextjs (react only)
- playground 🔴
- prefetching 🚫 nextjs (react only)
- react-native 🚫 react native (react only)
- rick-morty 🔴
- simple 🟢
- star-wars 🔴
- suspense 🔴
10 changes: 10 additions & 0 deletions examples/solid/basic-graphql-request/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"rules": {
"react/react-in-jsx-scope": "off",
"jsx-a11y/anchor-is-valid": "off"
}
}
4 changes: 4 additions & 0 deletions examples/solid/basic-graphql-request/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.yalc
yalc.lock
6 changes: 6 additions & 0 deletions examples/solid/basic-graphql-request/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Example

To run this example:

- `npm install`
- `npm run start`
16 changes: 16 additions & 0 deletions examples/solid/basic-graphql-request/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" />
<title>Solid App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.tsx" type="module"></script>
</body>
</html>
Loading