Skip to content

Commit 620a871

Browse files
committed
chore: Add Data fetching example to Aetherspace Docs
1 parent c1ef2ec commit 620a871

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

packages/@aetherspace/components/AetherIcon/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
There’s many different ways to use icons and icon sets in Aetherspace. Here’s the full list:
44

5-
- Third party SVG component icon libraries, like `@nandorojo/iconic` or `@nandorojo/heroicons`
5+
- Third party SVG component icon libraries (like `@nandorojo/iconic` or `@nandorojo/heroicons`)
66
→ SSR support, fast & easy, no layout shift on web, limited options
77
- Custom SVG components using `react-native-svg`
88
→ SSR support, can [convert from .svg file](https://transform.tools/svg-to-react-native), but could be more time-consuming
99
- Third party iconfont libraries, such as `@expo/vector-icons`
1010
→ Fast & easy, needs icon font preloaded, layout shift on web, locked out of SWC
1111
- Image icons through src urls
12-
→ Straight forward, easy to implement, not super optimised, layout shift on web
12+
→ Straight forward, easy, not super optimised, fixed colors, layout shift on web
1313

1414
### Best practices
1515

packages/@aetherspace/navigation/AetherPage/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,60 @@ To actually get the data from your GraphQL resolvers into the specific screens f
177177
- `AetherPage`, used to wrap your page component in a Next.js app-dir page under `/routes/`
178178

179179
We have a full working example of this in the Aetherspace demo app:
180-
- [/features/app-core/screens/HomeScreen.tsx#L39-L76](https://github.com/Aetherspace/green-stack-starter-demo/blob/main/features/app-core/screens/HomeScreen.tsx#L39-L76)
180+
- [/features/app-core/screens/HomeScreen.tsx#L39-L83](https://github.com/Aetherspace/green-stack-starter-demo/blob/main/features/app-core/screens/HomeScreen.tsx#L39-L83)
181181
- [/features/app-core/routes/index.tsx](https://github.com/Aetherspace/green-stack-starter-demo/blob/main/features/app-core/routes/index.tsx)
182182

183+
```tsx
184+
/* --- GraphQL & Data Fetching ----------------------------------------------------------------- */
185+
186+
/** -i- GraphQL query that will fetch all data we need for this screen */
187+
const getScreenDataQuery = `
188+
query($healthCheckArgs: HealthCheckArgs!) {
189+
healthCheck(args: $healthCheckArgs) {
190+
alive
191+
kicking
192+
echo
193+
baseURL
194+
}
195+
}
196+
`
197+
198+
/** -i- Function to get the GraphQL variables that will be used to fetch the data for this screen */
199+
const getHomeScreenArgs = (params: HomeScreenParams = {}) => ({
200+
healthCheckArgs: HomeParamsSchema.parse(params),
201+
})
202+
203+
/** -i- Function to actually fetch the data for this screen, where queryKey is likely the GQL query */
204+
const getHomeScreenData = async (queryKey: string, queryVariables?: HomeScreenParams) => {
205+
const queryData = queryKey || getScreenDataQuery
206+
const queryInput = queryVariables || getHomeScreenArgs() // Use defaults if not defined
207+
const { data } = await fetchAetherProps(queryData, queryInput)
208+
const { alive, kicking, echo } = data?.healthCheck || {}
209+
return { alive, kicking, customGreeting: echo } as HomeScreenProps
210+
}
211+
212+
/** -i- Bundled config for getting the screen data, including query, variables, and data fetcher */
213+
export const screenConfig = {
214+
query: getScreenDataQuery,
215+
getGraphqlVars: getHomeScreenArgs,
216+
getGraphqlData: getHomeScreenData,
217+
paramSchema: HomeParamsSchema,
218+
propSchema: HomePropsSchema,
219+
refetchOnMount: false,
220+
backgroundColor: '#FFFFFF',
221+
}
222+
223+
/* --- <HomeScreen/> --------------------------------------------------------------------------- */
224+
225+
export const HomeScreen = (props: AetherProps<typeof HomePropsSchema>) => {
226+
// Props & Screen Data Fetching (from screenConfig 👇)
227+
const [pageData] = useAetherRoute(props, screenConfig)
228+
const { customGreeting, alive, kicking, baseURL = BASE_URL } = pageData
229+
230+
// ...
231+
}
232+
```
233+
183234
But again, you may want to save some time by skipping the manual boilerplate entirely and use a generator instead:
184235

185236
## Generating GraphQL powered routes

packages/@aetherspace/scripts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
> Codegen in Aetherspace is focused on keeping your internal features and packages folders as transferrable between projects as possible. Therefore, it is limited to do only a few things:
44
5-
- Creating barrel files, as registries (abstracting imports and module linking)
6-
- Deduplicating file-based conventions (from modules to next.js app dir & expo-router app dir)
75
- Turborepo generators for easy creation of new routes, schemas and data-resolvers
6+
- Deduplicating file-based conventions (e.g. linking from modules to next.js & expo-router app dirs)
7+
- Creating barrel files to act as "registries" (e.g. abstracting imports and module linking)
88

99
The `packages/@registries` folder contains the results of all the automation scripts defined at `packages/@aetherspace/scripts`. These scripts are automatically run in development mode from the `withAutomation()` plugin in `apps/next/next.config.js`.
1010

0 commit comments

Comments
 (0)