0.5.33 • Published 7 days ago

@wundergraph/solid-query v0.5.33

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 days ago

WunderGraph Solid Query Integration

wunderctl

This package provides a type-safe integration of Solid Query with WunderGraph. Solid Query is a data fetching library for Solid.js.

Warning: Only works with WunderGraph.

Getting Started

npm install @wundergraph/solid-query @tanstack/solid-query

Before you can use the hooks, you need to modify your code generation to include the base typescript client.

// wundergraph.config.ts
configureWunderGraphApplication({
  // ... omitted for brevity
  codeGenerators: [
    {
      templates: [templates.typescript.client],
      // the location where you want to generate the client
      path: '../src/components/generated',
    },
  ],
});

Second, run wunderctl generate to generate the code.

Now you can configure the hooks. Create a new file, for example lib/wundergraph.ts and add the following code:

import { createHooks } from '@wundergraph/solid-query';
import { createClient, Operations } from './components/generated/client';

const client = createClient(); // Typesafe WunderGraph client

export const { createQuery, createMutation, createSubscription, createFileUpload, useUser, useAuth } =
  createHooks<Operations>(client);

In your App.tsx add QueryClientProvider:

import { QueryClient, QueryClientProvider } from '@tanstack/solid-query';

const queryClient = new QueryClient();

export default App() {
  return (
    <QueryClientProvider client={queryClient}>
      <div>...</div>
    </QueryClientProvider>
  );
}

Now you can use the hooks in your components:

createQuery

const weather = createQuery({
  operationName: 'Weather',
  input: { forCity: city },
});

createQuery (Live query)

const weather = createQuery({
  operationName: 'Weather',
  input: { forCity: city },
  liveQuery: true,
});

createSubscription

const weather = createSubscription({
  operationName: 'LiveWeather',
  input: {
    forCity: 'Berlin',
  },
});

createMutation

const mutation = createMutation({
  operationName: 'SetName',
});

mutation.mutate({ name: 'WunderGraph' });

await mutation.mutateAsync({ name: 'WunderGraph' });

createFileUpload

const uploader = useFileUpload();

uploader.upload({
  provider: 'minio',
  files: new FileList(),
});

await uploader.upload({
  provider: 'minio',
  files: new FileList(),
});

uploader.fileKeys; // files that have been uploaded

useAuth

const { login, logout } = useAuth();

login('github');

logout({ logoutOpenidConnectProvider: true });

useUser

const user = useUser();

user.data;

queryKey

You can use the queryKey helper function to create a unique key for the query in a typesafe way. This is useful if you want to invalidate the query after mutating.

const queryClient = useQueryClient();

const mutation = useMutation({
  operationName: 'SetName',
  onSuccess() {
    queryClient.invalidateQueries(queryKey({ operationName: 'Profile' }));
  },
});

mutation.mutate({ name: 'WunderGraph' });

Options

You can use all available options from Solid Query.

0.5.33

7 days ago

0.5.32

1 month ago

0.5.31

2 months ago

0.5.30

3 months ago

0.5.29

4 months ago

0.5.28

5 months ago

0.5.27

5 months ago

0.5.26

6 months ago

0.5.10

9 months ago

0.5.11

9 months ago

0.5.18

7 months ago

0.5.19

7 months ago

0.5.16

8 months ago

0.4.48

11 months ago

0.5.17

7 months ago

0.4.49

10 months ago

0.5.14

8 months ago

0.5.15

8 months ago

0.4.47

11 months ago

0.5.12

9 months ago

0.5.13

9 months ago

0.5.4

10 months ago

0.5.3

10 months ago

0.5.6

10 months ago

0.5.5

10 months ago

0.5.0

10 months ago

0.5.2

10 months ago

0.5.1

10 months ago

0.5.8

9 months ago

0.5.7

9 months ago

0.5.9

9 months ago

0.5.21

7 months ago

0.5.22

7 months ago

0.5.20

7 months ago

0.4.50

10 months ago

0.5.25

6 months ago

0.5.23

7 months ago

0.5.24

6 months ago

0.4.42

12 months ago

0.4.43

12 months ago

0.4.40

12 months ago

0.4.41

12 months ago

0.4.46

11 months ago

0.4.44

12 months ago

0.4.45

11 months ago

0.4.31

1 year ago

0.4.32

1 year ago

0.4.30

1 year ago

0.4.39

12 months ago

0.4.37

12 months ago

0.4.38

12 months ago

0.4.35

12 months ago

0.4.36

12 months ago

0.4.33

1 year ago

0.4.34

12 months ago

0.4.28

1 year ago

0.4.29

1 year ago

0.4.27

1 year ago

0.4.20

1 year ago

0.4.21

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.26

1 year ago

0.4.24

1 year ago

0.4.25

1 year ago

0.4.22

1 year ago

0.4.23

1 year ago

0.4.19

1 year ago

0.4.10

1 year ago

0.4.17

1 year ago

0.4.18

1 year ago

0.4.15

1 year ago

0.4.16

1 year ago

0.4.13

1 year ago

0.4.14

1 year ago

0.4.11

1 year ago

0.4.12

1 year ago

0.4.5

1 year ago

0.3.6

1 year ago

0.4.4

1 year ago

0.3.5

1 year ago

0.4.7

1 year ago

0.3.8

1 year ago

0.4.6

1 year ago

0.3.7

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.4.0

1 year ago

0.3.1

1 year ago

0.4.3

1 year ago

0.3.4

1 year ago

0.4.2

1 year ago

0.3.3

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago