Skip to content

Commit e7dfcf9

Browse files
authored
feat: add instructions for sharing schema between apps (#7742)
1 parent d383a42 commit e7dfcf9

File tree

2 files changed

+79
-0
lines changed
  • src/pages/[platform]/deploy-and-host/fullstack-branching

2 files changed

+79
-0
lines changed

src/pages/[platform]/deploy-and-host/fullstack-branching/mono-and-multi-repos/index.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,39 @@ frontend:
164164
paths:
165165
- node_modules/**/*
166166
```
167+
168+
<InlineFilter filters={['angular','javascript','nextjs','react','react-native','vue']}>
169+
## Sharing schema type definitions
170+
171+
If you're using Amplify Data, we recommend adding a `paths` entry in the `tsconfig.json` of your frontend app that points to the `amplify/data/resource.ts` file in your backend app to easily access your schema type definitions from your frontend apps.
172+
173+
First, cone your backend repo into the same parent directory as your frontend app, then add the following entry:
174+
175+
```json title="tsconfig.json" showLineNumbers={false}
176+
{
177+
"compilerOptions": {
178+
"paths": {
179+
"@/data-schema": ["../backend-app/amplify/data/resource"]
180+
}
181+
}
182+
}
183+
```
184+
185+
You can then import the `Schema` type from this path in your frontend code to get code completion and strong typing for your API calls:
186+
187+
```ts title="apps/admin-dashboard/page.tsx"
188+
import { generateClient } from "aws-amplify/data";
189+
import type { Schema } from "@/data-schema";
190+
191+
const client = generateClient<Schema>();
192+
193+
const createTodo = async () => {
194+
await client.models.Todo.create({
195+
content: window.prompt("Todo content?"),
196+
isDone: false,
197+
});
198+
}
199+
200+
```
201+
202+
</InlineFilter>

src/pages/[platform]/deploy-and-host/fullstack-branching/monorepos/index.mdx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,46 @@ Once the sandbox environment is running, you would also generate the configurati
112112
</InlineFilter>
113113

114114
- To locate the `App ID` for your backend application, navigate to the Amplify console and select your **backend-app**. On the Overview page, the `App ID` is displayed under the project name.
115+
116+
<InlineFilter filters={['angular','javascript','nextjs','react','react-native','vue']}>
117+
118+
```bash title="Terminal" showLineNumbers={false}
119+
npx ampx generate outputs --branch main --app-id BACKEND-APP-ID
120+
```
121+
</InlineFilter>
122+
123+
124+
<InlineFilter filters={['angular','javascript','nextjs','react','react-native','vue']}>
125+
126+
## Sharing schema type definitions
127+
128+
If you're using Amplify Data, we recommend adding a `paths` entry in your `tsconfig.json` file that points to the `amplify/data/resource.ts` file to easily access your schema type definitions from your frontend apps.
129+
130+
```json title="tsconfig.json" showLineNumbers={false}
131+
{
132+
"compilerOptions": {
133+
"paths": {
134+
"@/data-schema": ["./packages/my-shared-backend/amplify/data/resource"]
135+
}
136+
}
137+
}
138+
```
139+
140+
You can then import the `Schema` type from this path in your frontend code to get code completion and strong typing for your API calls:
141+
142+
```ts title="apps/admin-dashboard/page.tsx"
143+
import { generateClient } from "aws-amplify/data";
144+
import type { Schema } from "@/data-schema";
145+
146+
const client = generateClient<Schema>();
147+
148+
const createTodo = async () => {
149+
await client.models.Todo.create({
150+
content: window.prompt("Todo content?"),
151+
isDone: false,
152+
});
153+
}
154+
155+
```
156+
157+
</InlineFilter>

0 commit comments

Comments
 (0)