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.

Adding @auth directive breaks amplify push

See original GitHub issue

Describe the bug Whenever I add @auth to one of my API models, I get a Cannot read property 'fields' of undefined exception when running amplify push. I do have Cognito authentication set up with my app and that works fine.

Amplify CLI Version 4.22.0

To Reproduce Adding @auth to this model gives me the error:

type UserAccount
  @model
  @key(
    name: "accountsByUser"
    fields: ["cognitoUserID"]
    queryField: "accountsByUser"
  )
  @auth(rules: [{ allow: owner }]) {
  id: ID!
  cognitoUserID: String!
  institutionName: String!
  institutionID: String!
  accessKey: String!
}

Expected behavior Expected @auth to work fine.

Screenshots

 Cannot read property 'fields' of undefined
An error occurred during the push operation: Cannot read property 'fields' of undefined

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: 14.2

Additional context

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
attilahcommented, Sep 28, 2020

@apiel51 I was not able to reproduce the issue with the provided schema, but thanks for the details that helped to locate the issue and you are right, the root cause is that subscription is not part of the schema element which can happen as in @bever1337 's case when schema is manually defined, now I’m making a fix for @bever1337 's case so it will add subscription member even if schema is manually defined but does not have the subscription operations type added.

@apiel51 could you provide some more details, do you have schema in your schema file defined? I want to make sure that we’re covering the grounds, but based on the stacktrace my fix will cover it. If after PR merge and release you can still reproduce it, feel free to reopen the issue.

@bever1337 to add custom operations to Query or Mutation or Subscription you don’t need to define the schema element in the schema, GraphQL compilation in the CLI will handle that. So this piece is not needed:

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription
}
0reactions
github-actions[bot]commented, May 25, 2021

This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference - Feature Flags - AWS Amplify Docs
When a feature flag is added to the Amplify CLI it will be mentioned in the release notes and also this page will...
Read more >
AWS Amplify Features | Front-End Web & Mobile
Amplify Studio provides a visual interface for modeling data, adding authentication, authorization and managing users and groups. As you create backend ...
Read more >
Offline-first made easy with GraphQL, Amplify DataStore and ...
First, we are going to create the GraphQL API to service Chatty chatroom. To create it, we will use the following command: amplify...
Read more >
AWS-Amplify/Lobby - Gitter
After adding auth using the CLI, do I also need to create a user pool in ... try to run amplify push, it...
Read more >
@aws-amplify/graphql-model-transformer - npm
This would create and configure a single query field post(id: ID!): Post and no mutation fields. @auth. Object types that are annotated with...
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