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
I created a custom mutation is my models. This mutation can only be called by authenticated user and, among other things, create a User object defined in the models.
In the Lambda handler I use Amplify.configure then generate the client with Amplify.generateClient<Schema>(). However, client.models is undefined and so preventing me to call clients.models.User.get or clients.models.User.create.
My client and backend look correctly configured, indeed, if I replace with a graphql operation, I can get or create, using:
(awaitclient.graphql({query: createUser,variables: {input: {id: owner}},// <-- can't add an "owner" field and it's not populated by default})).data.createUser;
However, with this method, I can't specify an owner field, which is problematic. Using clients.models.User.create should resolve this issue by automatically populating the owner field, but, as explained above, it is unfortunately not working.
Thank you for your help.
The text was updated successfully, but these errors were encountered:
After digging documentation, I realized best practice for my use case is simply to use ownerDefinedIn when setting authorization, so I can work fine with client.graphql and a custom field for ownership.
However, even though I'm not blocked anymore with this missing models, the issue still remains. Why the models are not populated on Lambda? Are they supposed to only be used in the client?
@AdrKacz at the moment, only client.graphql is fully supported in lambdas. in order for client.models to work, the model introspection schema has to be available in the configuration (Amplify.configure()).
this requires some manual workarounds to ensure it's thee because of the way lambdas are bundled and deployed, they are not in sync with changes made to the amplify configuration on each deployment.
we have a page on accessing the graphql api from a lambda which also shows to use the graphql client rather than the models client for this reason:
Environment information
Data packages
Description
I created a custom mutation is my models. This mutation can only be called by authenticated user and, among other things, create a
User
object defined in the models.In the Lambda handler I use
Amplify.configure
then generate the client withAmplify.generateClient<Schema>()
. However,client.models
isundefined
and so preventing me to callclients.models.User.get
orclients.models.User.create
.My client and backend look correctly configured, indeed, if I replace with a
graphql
operation, I canget
orcreate
, using:However, with this method, I can't specify an
owner
field, which is problematic. Usingclients.models.User.create
should resolve this issue by automatically populating theowner
field, but, as explained above, it is unfortunately not working.Thank you for your help.
The text was updated successfully, but these errors were encountered: