You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The object returned from `defineFunction` can be passed directly to `allow.resource()` in the schema authorization rules. This will grant the function the ability to execute Query, Mutation, and Subscription operations against the GraphQL API. Use the `.to()` method to narrow down access to one or more operations.
64
71
65
-
```ts
72
+
```ts title="amplify/data/resource.ts"
66
73
const schema =a
67
74
.schema({
68
75
Todo: a.model({
69
76
name: a.string(),
70
-
description: a.string()
77
+
description: a.string(),
78
+
isDone: a.boolean()
71
79
})
72
80
})
73
81
// highlight-start
@@ -77,8 +85,6 @@ const schema = a
77
85
// highlight-end
78
86
```
79
87
80
-
When configuring function access, the function will be provided the API endpoint as an environment variable named `<defineDataName>_GRAPHQL_ENDPOINT`, where `defineDataName` is transformed to SCREAMING_SNAKE_CASE. The default name is `AMPLIFY_DATA_GRAPHQL_ENDPOINT` unless you have specified a different name in `defineData`.
81
-
82
88
<Calloutinfo>
83
89
84
90
Function access can only be configured on the schema object. It cannot be configured on individual models or fields.
@@ -89,86 +95,43 @@ Function access can only be configured on the schema object. It cannot be config
89
95
90
96
In the handler file for your function, configure the Amplify data client
Use the command below to generate GraphQL client code to call your data backend.
135
-
<Calloutinfo>
136
-
137
-
**Note**: We are working on bringing the end-to-end typed experience to connect to your data from within function resources without needing this step. If you'd like to provide feedback the experience or have early access, join our [Discord community](https://discord.gg/amplify).
**Note:** Whenever you update your data model, you will need to run the command above again.
149
-
118
+
When configuring Amplify with `getAmplifyDataClientConfig`, your function consumes schema information from an S3 bucket created during backend deployment with grants for the access your function need to use it. Any changes to this bucket outside of backend deployment may break your function.
150
119
</Callout>
151
120
152
121
Once you have generated the client code, update the function to access the data. The following code creates a todo and then lists all todos.
Run the command `npx ampx sandbox` to create the backend, then use the command below to generate GraphQL client code to call your data backend.
96
-
<Calloutinfo>
97
-
98
-
**Note**: We are working on bringing the end-to-end typed experience to connect to your data from within function resources without needing this step. If you'd like to provide feedback on the experience or want to have early access, join our [Discord community](https://discord.gg/amplify).
When configuring Amplify with `getAmplifyDataClientConfig`, your function consumes schema information from an S3 bucket created during backend deployment with grants for the access your function need to use it. Any changes to this bucket outside of backend deployment may break your function.
126
+
</Callout>
164
127
165
128
166
129
Lastly, set the newly created Function resource on your auth resource:
0 commit comments