aws-amplify / amplify-codegen

Amplify Codegen is a JavaScript toolkit library for frontend and mobile developers building Amplify applications.
Apache License 2.0
59 stars 59 forks source link

Unknown field argument owner when using owner rules in Datastore #117

Closed amin79 closed 2 years ago

amin79 commented 3 years ago

Describe the bug I'm using expo with amplify datastore. When I assign owner rule to a model, I get some warnings like

[WARN] 29:35.271 DataStore - Sync error, Connection failed: {"errors":[{"message":"Validation error of type UnknownArgument: Unknown field argument owner @ 'onDeleteUser'"}]}

When I create a record, it would be save locally but not sync with the dynamoDB table in cloud.

If I remove the owner rule and just use "allow: private", the data also be saved in the cloud, but there is no "owner" field in the table which I need it.

To Reproduce Here one of the models:

type Setting
  @model
  @auth(
    rules: [
      { allow: owner, identityClaim: "sub", operations: [read, create, update] }
      { allow: private, operations: [read] }
    ]
  ) {
  id: ID!
  currency: String!
  owner: String
}

Expected behavior I expected to have synced data in the cloud and also owner field in my table.

What is Configured? I use Cognito for authentication and authorization. Users login with their Google or Facebook accounts.

amhinson commented 3 years ago

@amin79 Could you share the following info:

I am able to reproduce this issue, and it appears to be related to codegen. I am not seeing an owner argument for the generated subscriptions in build/schema.graphql:

type Subscription {
  onCreatePost: Post @aws_subscribe(mutations: ["createPost"])
  onUpdatePost: Post @aws_subscribe(mutations: ["updatePost"])
  onDeletePost: Post @aws_subscribe(mutations: ["deletePost"])
}

Tranferring to CLI.

amin79 commented 3 years ago

@amhinson amplify version: 4.41.0

package.json:

{ "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", "eject": "expo eject" }, "dependencies": { "@aws-amplify/datastore": "^2.9.2", "@react-native-community/masked-view": "0.1.10", "@react-native-community/netinfo": "^5.9.9", "@react-navigation/bottom-tabs": "^5.11.2", "@react-navigation/native": "^5.8.10", "@react-navigation/stack": "^5.12.8", "@reduxjs/toolkit": "^1.5.0", "aws-amplify": "^3.3.13", "aws-amplify-react-native": "^4.2.10", "aws-appsync-react": "^4.0.1", "expo": "~40.0.0", "expo-font": "~8.4.0", "expo-localization": "~9.1.0", "expo-status-bar": "~1.0.3", "expo-web-browser": "~8.6.0", "formik": "^2.2.6", "geolib": "^3.3.1", "i18n-js": "^3.8.0", "immer": "^8.0.0", "moment": "^2.29.1", "native-base": "^2.13.15", "react": "16.13.1", "react-dom": "16.13.1", "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz", "react-native-appstate-hook": "^1.0.5", "react-native-dialog": "^6.1.2", "react-native-easy-grid": "^0.2.2", "react-native-gesture-handler": "~1.8.0", "react-native-keyboard-aware-scroll-view": "^0.9.3", "react-native-loading-spinner-overlay": "^2.0.0", "react-native-modal-datetime-picker": "^9.1.0", "react-native-reanimated": "~1.13.0", "react-native-root-siblings": "^4.1.0", "react-native-root-toast": "^3.2.1", "react-native-safe-area-context": "3.1.9", "react-native-screens": "~2.15.0", "react-native-sectioned-multi-select": "^0.8.1", "react-native-web": "~0.13.12", "react-redux": "^7.2.2", "react-timeago": "^5.2.0", "redux": "^4.0.5" }, "devDependencies": { "@babel/core": "~7.9.0" }, "private": true }

I could solve the problem by removing the api and create it again and it worked since today.

But again, I did some changes on the schema and when tried to push it, I got some errors because of my mistake. The I undo my changes and push it again and ran amplify codegene. It mans everything was configured as before. But again I get No Authorised to access error message.

kristjan97 commented 3 years ago

Having a similar issue, hoping there is a fix to this issue soon! Will be using API key auth in dev until this bug has been patched. There is some discussion about the issue in the Amplify discord #datastore-help section (this page has been referenced in there so you can find relevant messages by using this link)

duranmla commented 2 years ago

In my case, I was able to get rid of the warnings by updating the permissions of the model. Because by mistake I was allowing anyone logged in to have edit, update, delete permissions over the model. Once I update to make sure only owner can edit I solve the warning.

CleanShot 2021-10-04 at 14 44 20@2x
alharris-at commented 2 years ago

Hi @amin79, are you still encountering this issue?

alharris-at commented 2 years ago

Closing as not reproducible right now. We have significantly refactored the auth codegen and transformer logic with GraphQL v2, which has likely addressed the issues here.