aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.4k stars 2.11k forks source link

AdminQuery: API AdminQueries does not exist #9746

Closed stayingcool closed 2 years ago

stayingcool commented 2 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication, REST API, Storage

Amplify Categories

auth, storage, function, api, hosting

Environment information

``` # Put output below this line System: OS: macOS 12.2.1 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Memory: 906.59 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node Yarn: 1.22.17 - ~/projects/creative-tim/pna-multi-env/upload_pna/tax/node_modules/.bin/yarn npm: 6.14.4 - ~/.nvm/versions/node/v10.15.1/bin/npm Browsers: Brave Browser: 99.1.36.119 Chrome: 99.0.4844.84 Firefox: 98.0.2 Safari: 15.3 npmPackages: @apollo/client: ^3.3.2 => 3.4.16 @apollo/client/cache: undefined () @apollo/client/core: undefined () @apollo/client/errors: undefined () @apollo/client/link/batch: undefined () @apollo/client/link/batch-http: undefined () @apollo/client/link/context: undefined () @apollo/client/link/core: undefined () @apollo/client/link/error: undefined () @apollo/client/link/http: undefined () @apollo/client/link/persisted-queries: undefined () @apollo/client/link/retry: undefined () @apollo/client/link/schema: undefined () @apollo/client/link/utils: undefined () @apollo/client/link/ws: undefined () @apollo/client/react: undefined () @apollo/client/react/components: undefined () @apollo/client/react/context: undefined () @apollo/client/react/data: undefined () @apollo/client/react/hoc: undefined () @apollo/client/react/hooks: undefined () @apollo/client/react/parser: undefined () @apollo/client/react/ssr: undefined () @apollo/client/testing: undefined () @apollo/client/utilities: undefined () @apollo/client/utilities/globals: undefined () @apollo/link-ws: ^2.0.0-beta.3 => 2.0.0-beta.3 @auth0/auth0-spa-js: ^1.6.3 => 1.19.2 @aws-amplify/ui-react: ^0.2.7 => 0.2.38 ag-grid-base-icons: 1.0.0 ag-grid-community: ^22.1.1 => 22.1.1 ag-grid-react: ^22.1.1 => 22.1.1 apexcharts: ^3.15.3 => 3.29.0 auth0-js: ^9.12.2 => 9.17.0 availity-reactstrap-validation: ^2.6.1 => 2.7.1 aws-amplify: ^3.3.4 => 3.4.3 aws-sdk: ^2.716.0 => 2.1018.0 axios: ^0.19.2 => 0.19.2 (0.21.1) axios-mock-adapter: ~1.17.0 => 1.17.0 babel-plugin-react-intl: ^5.1.18 => 5.1.18 bootstrap: ^4.4.1 => 4.6.1 chart.js: ^2.9.3 => 2.9.4 chroma-js: ~2.1.0 => 2.1.2 classnames: ~2.2.6 => 2.2.6 draft-js: ^0.11.4 => 0.11.7 file-saver: ^2.0.2 => 2.0.5 firebase: ^7.10.0 => 7.24.0 firebase/analytics: undefined () firebase/app: undefined () firebase/auth: undefined () firebase/database: undefined () firebase/firestore: undefined () firebase/firestore/memory: undefined () firebase/functions: undefined () firebase/installations: undefined () firebase/messaging: undefined () firebase/performance: undefined () firebase/remote-config: undefined () firebase/storage: undefined () flatpickr: ^4.6.6 => 4.6.9 formik: ^2.1.3 => 2.2.9 glamor: ^2.20.40 => 2.20.40 graphql: ^15.4.0 => 15.7.2 (14.0.0) history: ^4.10.1 => 4.10.1 intl-messageformat: ^7.8.4 => 7.8.4 jquery: ~3.4.1 => 3.4.1 jsonwebtoken: ~8.5.1 => 8.5.1 leaflet: ^1.6.0 => 1.7.1 match-sorter: ~4.0.2 => 4.0.2 moment: ~2.24.0 => 2.24.0 moment-timezone: ^0.5.31 => 0.5.33 namor: ^2.0.2 => 2.0.3 node-sass: ^4.13.1 => 4.14.1 postcss-rtl: ^1.5.0 => 1.7.3 prismjs: ^1.19.0 => 1.25.0 prop-types: ~15.7.2 => 15.7.2 query-string: ^6.10.1 => 6.14.1 (4.3.4) rc-slider: ^9.1.0 => 9.7.4 react: ^16.12.0 => 16.14.0 react-apexcharts: ^1.3.6 => 1.3.9 react-app-rewire-postcss: ^3.0.2 => 3.0.2 react-app-rewired: ^2.1.5 => 2.1.8 react-beautiful-dnd: ^12.2.0 => 12.2.0 react-big-calendar: ^0.24.0 => 0.24.6 react-bootstrap-sweetalert: ^5.1.9 => 5.2.0 react-chartjs: ^1.2.0 => 1.2.0 react-chartjs-2: ^2.9.0 => 2.11.2 react-contexify: ~4.1.1 => 4.1.1 react-copy-to-clipboard: ~5.0.2 => 5.0.4 react-countdown-now: ~2.1.2 => 2.1.2 react-country-flag: ^2.0.1 => 2.3.1 react-data-table-component: ^6.2.3 => 6.11.8 react-dom: ^16.12.0 => 16.14.0 react-draft-wysiwyg: ^1.14.4 => 1.14.7 react-dropzone: ^10.2.1 => 10.2.2 react-feather: ~2.0.3 => 2.0.9 react-flatpickr: ^3.10.6 => 3.10.7 react-hammerjs: ^1.0.1 => 1.0.1 react-hook-form: ^5.7.2 => 5.7.2 react-id-swiper: ~2.4.0 => 2.4.0 react-idle-timer: ^4.5.0 => 4.6.4 react-infinite-scroll-component: ^5.0.5 => 5.1.0 react-input-mask: ~2.0.4 => 2.0.4 react-intl: ^3.11.0 => 3.12.1 react-joyride: ^2.2.1 => 2.3.2 react-leaflet: ^2.6.1 => 2.8.0 react-numeric-input: ~2.2.3 => 2.2.3 react-paginate: ~6.3.2 => 6.3.2 react-perfect-scrollbar: ^1.5.5 => 1.5.8 react-redux: ~7.1.3 => 7.1.3 react-reveal: ^1.2.2 => 1.2.2 react-ripples: ^2.2.1 => 2.2.1 react-router-dom: ~5.1.2 => 5.1.2 react-scripts: ^3.3.0 => 3.4.4 react-scroll-up: ~1.3.3 => 1.3.7 react-select: ~3.0.8 => 3.0.8 react-sidebar: ~3.0.2 => 3.0.2 react-table: ~6.10.0 => 6.10.3 react-toastify: ^5.5.0 => 5.5.0 react-toggle: ~4.1.1 => 4.1.2 react-treebeard: ~3.2.3 => 3.2.4 reactstrap: ^8.10.0 => 8.10.1 recharts: ~1.8.5 => 1.8.5 redux: ^4.0.5 => 4.1.2 redux-debounced: ~0.5.0 => 0.5.0 redux-thunk: ~2.3.0 => 2.3.0 reselect: ^4.0.0 => 4.1.1 styled-components: ^5.0.1 => 5.3.3 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () subscriptions-transport-ws: ^0.9.18 => 0.9.19 swiper: ^5.3.0 => 5.4.5 use-debounce: ^5.0.0 => 5.2.1 xlsx: ^0.15.5 => 0.15.6 yarn: ^1.21.1 => 1.22.17 yup: ^0.28.1 => 0.28.5 npmGlobalPackages: @angular/cli: 8.0.3 @aws-amplify/cli: 4.25.0 @quasar/cli: 1.1.0 @vue/cli: 4.5.7 dynamodb-admin: 4.0.0 expo-cli: 4.1.6 http-server: 0.12.3 json-server: 0.17.0 npm: 6.14.4 typescript: 3.5.3 ```

Describe the bug

AdminQuery is returning an exception "API AdminQueries does not exist"

The REST endpoint is still returning the same error.

Can you provide some hints to resolve this issue?

Expected behavior

The AdminQueries API should return the list of groups for a user.

Reproduction steps

Add the admin query as documented Invoke the above-mentioned function (code provided above) The API fails and the exception gets caught in the catch block and the error shows "API AdminQueries does not exist" I cannot upgrade the version of amplify cli as of now. This is a working setup and is a part of my production setup that suddenly stopped working.

Code Snippet

// Put your code below this line.
// The function that I have to list the groups of a user (listGroupsForUser):
async isQCAuditor(cognitoUsername) {
    if (!cognitoUsername) return false;

    let isQcAuditor = false;
    let nextToken;
    let apiName = "AdminQueries";
    let path = "/listGroupsForUser";
    let myInit = {
      queryStringParameters: {
        username: cognitoUsername,
        token: nextToken
      },
      headers: {
        "Content-Type": "application/json",
        Authorization: `${(await Auth.currentSession())
          .getAccessToken()
          .getJwtToken()}`
      }
    };

    try {
      const { NextToken, ...cognitoGroups } = await API.get(
        apiName,
        path,
        myInit
      );
      nextToken = NextToken;

      for (let group of cognitoGroups.Groups) {
        if (group.GroupName === "qcauditor") {
          isQcAuditor = true;
          break;
        }
      }
    } catch (e) {
      console.log(e);
    }

    return isQcAuditor;
  }

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

stayingcool commented 2 years ago

I have asked for help in Discord community as well: https://discord.com/channels/705853757799399426/957602716312543262

vyomr13 commented 2 years ago
Screen Shot 2022-04-01 at 12 40 07 PM

Hi,

We were unable to reproduce this with newer version of Amplify. Would you be able to just upgrade aws-amplify and the UI package. The version of these packages you have installed are causing duplicates in the dependency tree. For more information you can check this page https://docs.amplify.aws/lib/troubleshooting/upgrading/q/platform/js/#check-for-duplicate-versions

npm i aws-amplify@latest @aws-amplify/ui-react@1.x.x

After upgrading please try to make a request to the API and let us know if the issue persists.

stayingcool commented 2 years ago

Hi @vyomr13

I did the following:

package.json shows that these libraries are upgraded:

image

Then started the webserver and observed that the issue is fixed.

What baffles me is that this issue just showed up in the production environment all of a sudden. The solution offered is to upgrade two major libraries that warrant testing the entire application thoroughly before we can deploy this into production.

Is there a way to debug this issue and address the root cause without the library upgrade?

vyomr13 commented 2 years ago

We made sure to only bump up the versions that should not create any major breaking changes. We kept the @aws-amplify/ui-react package at v1 because v2 is a rewrite and there would be a lot of breaking changes. You could do some testing as a workflow just in case but the behavior should not change. The only breaking change between aws-amplify v3 and v4 is related to React Native. The root cause of the issue is incompatible versions of packages causing duplicates in the dependency tree. This results in multiple instances of the Amplify class and unexpected behavior (usually missing configuration) as a side effect.

stayingcool commented 2 years ago

@vyomr13 - Ok, I'll take a look at "incompatible versions of packages causing duplicates in the dependency tree"

I upgraded the libraries and the issue is fixed. Thank you for your time and effort.

github-actions[bot] commented 1 year ago

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 amplify-help forum.