Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v6 upgrade causing errors on subscription, mutations #12621

Closed
3 tasks done
OperationalFallacy opened this issue Nov 22, 2023 · 4 comments
Closed
3 tasks done

v6 upgrade causing errors on subscription, mutations #12621

OperationalFallacy opened this issue Nov 22, 2023 · 4 comments
Assignees
Labels
GraphQL Related to GraphQL API issues investigating This issue is being investigated Next.js

Comments

@OperationalFallacy
Copy link

Before opening, please confirm:

JavaScript Framework

Next.js

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

# Put output below this line
  System:
    OS: macOS 13.6.1
    CPU: (8) arm64 Apple M2
    Memory: 51.16 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.n/bin/node
    Yarn: 1.22.19 - ~/.n/bin/yarn
    npm: 9.6.7 - ~/.n/bin/npm
  Browsers:
    Brave Browser: 116.1.57.47
    Chrome: 118.0.5993.117
    Safari: 17.1
  npmPackages:
    @aws-amplify/api-graphql: ^4.0.0 => 4.0.4 
    @aws-amplify/api-graphql/internals:  undefined ()
    @aws-amplify/api-graphql/internals/server:  undefined ()
    @aws-amplify/cli: 12.8.2 => 12.8.2 
    @aws-sdk/client-secrets-manager: ^3.418.0 => 3.429.0 
    @aws-sdk/client-sso: ^3.418.0 => 3.429.0 
    @aws-sdk/credential-provider-sso: ^3.418.0 => 3.429.0 
    @smithy/protocol-http: ^3.0.5 => 3.0.7 
    @smithy/signature-v4: ^2.0.9 => 2.0.11 
plus some 

  npmGlobalPackages:
    npm: 10.2.4
    yarn: 1.22.21

Describe the bug

Getting unauthorized for the models that were working ok with v5

For example

type User @model @auth(rules: [
    { allow: owner, operations: [read, update], identityClaim: "email::sub" },
  ]) {
  userEmail: ID! @primaryKey
  name: String!
  xxx: [xxx] @hasMany(indexName: "userxxxByxxx", fields: ["userEmail"] )
  owner: String @auth(rules: [{ allow: owner, operations: [read, delete], identityClaim: "email::sub"  }])
  openRequests: Int @auth(rules: [{ allow: owner, operations: [read], identityClaim: "email::sub"  }])
}
{
    "recoverySuggestion": "Ensure app code is up to date, auth directives exist and are correct on each model, and that server-side data has not been invalidated by a schema change. If the problem persists, search for or create an issue: https://github.com/aws-amplify/amplify-js/issues",
    "localModel": null,
    "message": "Connection failed: {\"errors\":[{\"errorType\":\"Unauthorized\",\"message\":\"Not Authorized to access onUpdateUser on type Subscription\"}]}",
    "model": "User",
    "operation": "Update",
    "errorType": "Unauthorized",
    "process": "subscribe",
    "remoteModel": null,
    "cause": {
        "errors": [
            {
                "message": "Connection failed: {\"errors\":[{\"errorType\":\"Unauthorized\",\"message\":\"Not Authorized to access onUpdateUser on type Subscription\"}]}"
            }
        ]
    }
}

Expected behavior

Given the custom mutation with Lambda works, as well as refreshing data (refresh page) - the subscription should be working, too

Reproduction steps

upgrade amplify to v6...

Code Snippet

      <Flex justifyContent="space-between" maxWidth="42rem" padding="1rem" width="100%">
        <xxxCardCollection
          overrideItems={({ item, index }) => {
            return xxxComponent({
              item,
              handleXxxSubmission,
              generatingXxx: state.generatingXxx,
            });
          }}
        />
      </Flex>

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@OperationalFallacy OperationalFallacy added the pending-triage Issue is pending triage label Nov 22, 2023
@cwomack cwomack added GraphQL Related to GraphQL API issues Next.js labels Nov 22, 2023
@cwomack
Copy link
Contributor

cwomack commented Nov 22, 2023

@OperationalFallacy, thank you for opening this issue. Did you get a chance to see the v6 Migration Guide (specifically the "API (GraphQL) section)"? The syntax will be difference for any subscriptions and mutations, but if you can share the frontend code that is calling the GraphQL API's that would help too!

@cwomack cwomack self-assigned this Nov 22, 2023
@cwomack cwomack added investigating This issue is being investigated and removed pending-triage Issue is pending triage labels Nov 22, 2023
@OperationalFallacy
Copy link
Author

OperationalFallacy commented Nov 23, 2023

I had only one mutation via lambda (below), I've updated it - thanks for pointing out.

Still getting these errors. I believe they are from the code for collections

      const response= await client.graphql({
        query: requestxxx,
        variables: {
          input: {
            xxx: xxx,
          }
        }
      })
      console.log('response', response.data.requestxxx)
      // const response: xxxResponse | null = await xxx({
      //   xxx: xxx,
      // });
      ```
      
There is bunch of errors for all models I believe, which is strange because I use only a few in collection - not all. Why is it even complaining about subscription to every model?

@chrisbonifacio
Copy link
Contributor

chrisbonifacio commented Nov 27, 2023

Hi @OperationalFallacy can you provide some more relevant code snippets and share the output errors?

I had only one mutation via lambda (below)

Can you explain this a bit more? Are you calling client.graphql inside of a Lambda function?

Lastly, I'm curious if you have DataStore enabled. Do you see that there are errors for create, update, and delete subscriptions on all models? If DataStore is enabled, that might explain those errors and we can work from there.

@OperationalFallacy
Copy link
Author

Hey @chrisbonifacio, please see that linked ticket. The author mentioned how to patch this bug in the amplify lib. It fixed the problem described here (collection component with datastore enabled). I'm closing this issue in favor of #12590

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL Related to GraphQL API issues investigating This issue is being investigated Next.js
Projects
None yet
Development

No branches or pull requests

4 participants