aws-amplify / amplify-codegen

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

Custom Subscription types create invalid typescript #756

Closed rafaelfaria closed 9 months ago

rafaelfaria commented 10 months ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

GraphQL API

Amplify Categories

api

Environment information

``` # Put output below this line System: OS: macOS 14.1 CPU: (8) arm64 Apple M1 Pro Memory: 293.28 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.1.1 - ~/.nvm/versions/node/v16.18.1/bin/npm Browsers: Chrome: 119.0.6045.123 Safari: 17.1 npmPackages: bybit-api: ^3.7.6 => 3.7.6 npmGlobalPackages: bunyan: 1.8.15 camera.ui: 1.1.17 corepack: 0.14.1 npm-check-updates: 16.8.0 npm: 9.1.1 pretty: 2.0.0 serverless: 3.25.1 ```

Describe the bug

In order to go around the private authentication, I had to create a custom subscription type.

type Subscription {
  onCreateSignalPublic: Signal
      @aws_subscribe(mutations: ["createSignal"])
      @aws_iam
      @aws_cognito_user_pools
  onUpdateSignalPublic: Signal
      @aws_subscribe(mutations: ["updateSignal"])
      @aws_iam
      @aws_cognito_user_pools
  onDeleteSignalPublic: Signal
      @aws_subscribe(mutations: ["deleteSignal"])
      @aws_iam
      @aws_cognito_user_pools
}

When amplify generates the APIs, i am getting typescript errors on all custom types.

ERROR in src/lib/amplify/graphql/subscriptions.ts:82:12
TS2724: '"/Users/username/myApps/app/src/lib/amplify/API"' has no exported member named 'OnCreateSignalPublicSubscriptionVariables'. Did you mean 'OnCreateSignalSubscriptionVariables'?
    80 | }
    81 | ` as GeneratedSubscription<
  > 82 |   APITypes.OnCreateSignalPublicSubscriptionVariables,
       |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    83 |   APITypes.OnCreateSignalPublicSubscription
    84 | >;
    85 | export const onUpdateSignalPublic = /* GraphQL */ `subscription OnUpdateSignalPublic {

Expected behavior

I expect not to have ay typescript error :)

Reproduction steps

  1. Create a model

    @auth(
    rules: [
      { allow: owner, operations: [create] },
      { allow: private, provider: iam },
      { allow: groups, operations: [read, update, delete], groups: ["Admin"] }
    ]
    ) {
    ....
    }
  2. create a custom public. subscription

type Subscription {
  onCreateSignalPublic: Signal
      @aws_subscribe(mutations: ["createSignal"])
      @aws_iam
      @aws_cognito_user_pools
  onUpdateSignalPublic: Signal
      @aws_subscribe(mutations: ["updateSignal"])
      @aws_iam
      @aws_cognito_user_pools
  onDeleteSignalPublic: Signal
      @aws_subscribe(mutations: ["deleteSignal"])
      @aws_iam
      @aws_cognito_user_pools
}
  1. amplify api gql-compile && amplify codegen

Code Snippet

// Put your code below this line.

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

cwomack commented 9 months ago

Hello, @rafaelfaria and thank you for opening this issue. Could you clarify which version of Amplify you're currently or share your package.json? Thanks!

chrisbonifacio commented 9 months ago

Hi @rafaelfaria 👋 we're going to transfer this issue to the amplify-codegen repo for better support as it seems more related to that.

dpilch commented 9 months ago

Fixed by https://github.com/aws-amplify/amplify-codegen/pull/737. Please upgrade to the latest version of the CLI.