-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
791a388
commit a952a04
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
slug: /next/gqty-intro | ||
title: Introduction to GQty | ||
description: Faust.js uses GQty under the hood as a GraphQL client | ||
--- | ||
|
||
Faust uses GQty under the hood. | ||
|
||
GQty is a fundamentally new approach to a GraphQL client. GQty works by generating queries at runtime based on the data your app consumes. This means you no longer have to write queries by hand. | ||
|
||
## How it works | ||
|
||
Take the following example code: | ||
|
||
```tsx | ||
import { client } from 'client'; | ||
|
||
export default function Page() { | ||
const { useQuery } = client; | ||
const generalSettings = useQuery().generalSettings; | ||
|
||
return ( | ||
<> | ||
<h1>{generalSettings.title}</h1> | ||
<p>{generalSettings.description}</p> | ||
</> | ||
); | ||
} | ||
``` | ||
|
||
This would result in the following query being generated automatically: | ||
|
||
```graphql | ||
query { | ||
generalSettings { | ||
title | ||
description | ||
} | ||
} | ||
``` | ||
|
||
For further reading into how GQty works, check out the [GQty "What is it & why" docs](https://gqty.dev/docs/intro). | ||
|
||
## GQty React Hooks | ||
|
||
Faust.js exports the [GQty React hooks](https://gqty.dev/docs/react/fetching-data#fetching-data-with-react) from the `client`. They can be used as so: | ||
|
||
```tsx | ||
import { client } from 'client'; | ||
|
||
export default function Page() { | ||
const { | ||
useQuery, | ||
usePaginatedQuery, | ||
useTransactionQuery, | ||
useLazyQuery, | ||
useRefetch, | ||
prepareQuery, | ||
} = client; | ||
|
||
return <>...</>; | ||
} | ||
``` | ||
|
||
You can find the docs for each of these hooks below: | ||
|
||
- [useQuery](https://gqty.dev/docs/react/fetching-data#usequery) | ||
- [usePaginatedQuery](https://gqty.dev/docs/react/fetching-data#usepaginatedquery) | ||
- [useTransactionQuery](https://gqty.dev/docs/react/fetching-data#usetransactionquery) | ||
- [useLazyQuery](https://gqty.dev/docs/react/fetching-data#uselazyquery) | ||
- [useRefetch](https://gqty.dev/docs/react/fetching-data#userefetch) | ||
- [prepareQuery](https://gqty.dev/docs/react/fetching-data#preparequery) | ||
|
||
## Further Reading | ||
|
||
For most cases, GQty related functionality is covered in the [GQty docs](https://gqty.dev/docs). Some of the common use cases are: | ||
|
||
- [Fetching data in React](https://gqty.dev/docs/react/fetching-data) | ||
- [Using Mutations in React](https://gqty.dev/docs/react/mutations) | ||
- [Fetching data in `getStaticProps` or `getServerSideProps` with `inlineResolved`](https://gqty.dev/docs/client/fetching-data#inlineresolved) | ||
- [High level overview how GQty works](https://gqty.dev/docs/intro/how-it-works) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a952a04
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch site-dev was deployed successfully
Your environment Development of app faustjs-site was successfully updated
View build logs: https://my.wpengine.com/atlas#/faustjs-site/cixzyt38dn5ak04xxcqc36lf/jqfbp0padianlzeq9dsv07vu
View your environment URL: https://hcixzyt38dn5ak04xxcqc36lf.js.wpenginepowered.com