question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DataStore with @auth - subscriptionError ... MissingFieldArgument: Missing field argument editors

See original GitHub issue

Describe the bug

I built a React Native App and I am following the amplify docs to add owner authorization. I am using withAuthenticator to register and sign in users through AWS Cognito.

Adding an @auth rule to a model with multiple editors will throw a subscription Error :

DataStore - subscriptionError Connection failed: {“errors”:[{“message”:“Validation error of type MissingFieldArgument: Missing field argument editors @ ‘onCreateDraft’”}]}

Having just one owner won’t generate any errors.

To Reproduce Steps to reproduce the behavior:

  1. Add @auth parameter to a graphQL model
type Draft @model
  @auth(rules: [
    { allow: owner }
  ]) {
  id: ID!
  title: String!
  content: String
  owner: String
}
  1. Update @auth parameter with multiple editors
type Draft @model
  @auth(rules: [
     { allow: owner, ownerField: "editors", operations: [update, read] }
  ]) {
  id: ID!
  title: String!
  content: String
  owner: String
  editors: [String]
}
  1. Run amplify update api , amplify push, npm run amplify-modelgem

  2. Run the app locally and see the error (I am using a “GroceryList” model instead of “Draft”): image

Expected behavior I am expecting the app to run without errors

Code Snippet

type Product @model 
 @auth(rules: [
    { allow: owner },
  ]){
  id: ID!
  groceryList: GroceryList @connection(name: "GroceryListProducts")
  name: String!
  checked: Boolean!
  unit: String!
  quantity: Int!
  category: String!
}

type GroceryList @model 
 @auth(rules: [
     { allow: owner, ownerField: "editors", operations: [update, read] },
  ]){
  id: ID!
  name: String!
  description: String
  products: [Product] @connection(name: "GroceryListProducts")
  owner: String
  editors: [String]
}
import React from "react";
import Amplify from "aws-amplify";
import config from "./aws-exports";
import { withAuthenticator } from "aws-amplify-react-native";

Amplify.configure({
  ...config,
  Analytics: {
    disabled: true,
  },
});

const App = () => {
  return (
     ....
  );
};

export default withAuthenticator(App);

What is Configured?

Output of running npx envinfo --system --binaries --browsers --npmPackages --npmGlobalPackages

System:
    OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 5.38 GB / 15.78 GB
  Binaries:
    Node: 12.16.2 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 86.0.4240.111
    Edge: Spartan (44.18362.449.0)
    Internet Explorer: 11.0.18362.1
  npmPackages:
    @babel/core: ~7.9.0 => 7.9.6
    @iconify/icons-mdi: ^1.0.142 => 1.0.142
    @iconify/react: ^1.1.3 => 1.1.3
    @react-native-community/masked-view: 0.1.10 => 0.1.10
    @react-native-community/netinfo: 5.9.6 => 5.9.6
    @react-native-community/picker: 1.6.6 => 1.6.6
    @react-navigation/bottom-tabs: ^5.9.1 => 5.9.1
    @react-navigation/native: ^5.7.5 => 5.7.5
    @react-navigation/stack: ^5.9.2 => 5.9.2
    aws-amplify: ^3.3.2 => 3.3.2
    aws-amplify-react-native: ^4.2.7 => 4.2.7
    babel-polyfill: ^6.26.0 => 6.26.0
    expo: ~39.0.2 => 39.0.3
    expo-font: ^8.3.0 => 8.3.0
    expo-splash-screen: ^0.6.2 => 0.6.2
    expo-status-bar: ~1.0.2 => 1.0.2
    ini: ^1.3.5 => 1.3.5
    inquirer: ^6.5.1 => 6.5.2
    jest: ^26.4.2 => 26.4.2
    react: 16.13.1 => 16.13.1
    react-dom: 16.13.1 => 16.13.1
    react-native: https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz => 0.63.2
    react-native-gesture-handler: ~1.7.0 => 1.7.0
    react-native-reanimated: ~1.13.0 => 1.13.1
    react-native-safe-area-context: 3.1.4 => 3.1.4
    react-native-screens: ~2.10.1 => 2.10.1
    react-native-web: ~0.13.12 => 0.13.14
    react-redux: ^7.2.1 => 7.2.1
    react-redux-loading-bar: ^5.0.0 => 5.0.0
    react-test-renderer: ^16.13.1 => 16.13.1
    redux: ^4.0.5 => 4.0.5
    redux-thunk: ^2.3.0 => 2.3.0
  npmGlobalPackages:
    @aws-amplify/cli: 4.31.1
    @ionic/cli: 6.7.0
    bower: 1.8.8
    create-react-native-app: 3.1.0
    exp: 57.2.1
    expo-cli: 3.27.12
    express-generator: 4.16.1
    gulp: 4.0.2
    sequelize-cli: 6.1.0
    serverless: 1.71.3
    sharp-cli: 1.14.1
    wscat: 4.0.0

Environment:

  • Browser [Google Chrome]

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
hanna-beckercommented, Jan 17, 2021

This is also a limitation for my use case. We’re creating a tool where groups of people collaborate on projects. It works fine so far with the non-Datastore API (String array of userIDs per project as owner field), but we were really keen on upgrading to Datastore for the offline features, cascading mutations, more intuitive API, etc. We’ll be really happy when this becomes available. 😃

4reactions
hmisonnecommented, Nov 11, 2020

Hi @undefobj ,

In my use case, I am building a Grocery List App for shoppers who want to share and update a grocery list. It is the same concept as Tricount or Slitwise where users share expenses and can see live updates.

Having just one owner is not compatible with my concept since I need multiple users to get access to one grocery list. Not having the @auth directive is not ideal since the users will receive the data from the entire database.

The only way I found to work around this issue was to use SelectiveSync, but it comes with a lot of challenges:

  • Waiting for the user to be authentificated before triggering the sync #7128
  • Making sure the datastore is reflecting the latest state before dispatching Redux actions #7160
  • Clear items from DataStore which are no longer included in selective sync expression #7134
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get AWS Amplify's DataStore to sync between user ...
... an array of owners as an auth rule: DataStore with @auth - subscriptionError ... MissingFieldArgument: Missing field argument editors.
Read more >
Getting Started with AWS Amplify DataStore Multi-Auth for iOS
This article will cover how to get up and running with multiple authorization types for Amplify DataStore so you can keep your users'...
Read more >
Unknown field argument owner @ 'onCreateXYZ' - Science Fare
I've run into this when I had a model type two cognito @auth directives, e.g. @auth(rules: [ { allow: private, operations: [read] }...
Read more >
validation error of type missingfieldargument - You.com
DataStore - Validation error of type MissingFieldArgument: Missing . ... the below schema type Recipe @model @auth(rules: [ { allow: owner, provider: oidc....
Read more >
@aws-amplify/datastore | Yarn - Package Manager
The JS export has been removed from @aws-amplify/core in favor of exporting the functions it contained. Any calls to Amplify.Auth , Amplify ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found