aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.33k stars 248 forks source link

There's no constant named 'GET' in ModelOperation constants #2526

Closed EricDunaway closed 1 year ago

EricDunaway commented 1 year ago

Description

The documentation describes the @auth directive as supporting the following operations

  create
  update
  delete
  read # Short-hand to allow "get", "list", "sync", "listen", and "search"

  get # Retrieves an individual item
  list # Retrieves a list of items
  sync # Enables ability to sync offline/online changes (including via DataStore)
  listen # Subscribes to real-time changes
  search # Enables ability to search using @searchable directive

Docs: Authorization rules

I get an error of Error: Member not found: 'GET'. when trying to build with models generated from a schema with a directive such as @auth(rules: [{allow: owner, operations: [get]}])

Looking at the source for the package the granular read operations are not available. enum ModelOperation { CREATE, UPDATE, DELETE, READ } (src: packages/amplify_core/lib/src/types/models/auth_rule.dart)

Categories

Steps to Reproduce

  1. Create a schema using @auth(rules: [{allow: owner, operations: [get]}]) or any of the granular read operations
  2. Generate models amplify codegen models
  3. Execute flutter run
  4. See the build errors about the missing constants

Screenshots

Platforms

Android Device/Emulator API Level

API 27

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.3)
[✓] VS Code (version 1.74.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

! Doctor found issues in 2 categories.

Dependencies

Dart SDK 2.18.6
Flutter SDK 3.3.10
aquaventure 1.0.0+1

dependencies:
- amplify_api 1.0.0-next.2+1 [amplify_api_android amplify_api_ios amplify_core amplify_flutter async aws_common collection connectivity_plus flutter json_annotation meta plugin_platform_interface stream_transform web_socket_channel]
- amplify_auth_cognito 1.0.0-next.2+1 [amplify_auth_cognito_android amplify_auth_cognito_dart amplify_auth_cognito_ios amplify_core amplify_flutter amplify_secure_storage async flutter flutter_web_plugins meta path plugin_platform_interface]
- amplify_authenticator 1.0.0-next.1+3 [amplify_auth_cognito amplify_core amplify_flutter async aws_common collection flutter flutter_localizations intl meta smithy stream_transform]
- amplify_datastore 1.0.0-next.2 [flutter amplify_datastore_plugin_interface amplify_core plugin_platform_interface meta collection async]
- amplify_flutter 1.0.0-next.2 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios amplify_secure_storage aws_common collection flutter meta plugin_platform_interface]
- amplify_storage_s3 1.0.0-next.2+1 [amplify_core amplify_db_common amplify_storage_s3_dart aws_common flutter meta path_provider]
- calendar_date_picker2 0.3.5 [flutter]
- carousel_slider 4.2.1 [flutter]
- country_pickers 2.0.0 [flutter]
- cupertino_icons 1.0.5
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.1.1 [flutter bloc provider]
- flutter_switch 0.3.2 [flutter]
- font_awesome_flutter 10.3.0 [flutter]
- go_router 4.5.1 [collection flutter flutter_web_plugins logging meta]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- image_picker 0.8.6 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- lottie 1.4.3 [archive flutter path vector_math]
- pin_code_fields 7.4.0 [flutter]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- webview_flutter 4.0.1 [flutter webview_flutter_android webview_flutter_platform_interface webview_flutter_wkwebview]

transitive dependencies:
- amplify_api_android 1.0.0-next.2 [flutter]
- amplify_api_ios 1.0.0-next.2 [amplify_core flutter]
- amplify_auth_cognito_android 1.0.0-next.2 [flutter]
- amplify_auth_cognito_dart 0.3.1 [amplify_core amplify_secure_storage_dart async aws_common aws_signature_v4 built_collection built_value collection convert crypto fixnum http intl js json_annotation meta oauth2 path smithy smithy_aws stream_transform uuid worker_bee]
- amplify_auth_cognito_ios 1.0.0-next.2 [amplify_core flutter]
- amplify_core 1.0.0-next.2+1 [async aws_common aws_signature_v4 collection intl json_annotation logging meta retry uuid]
- amplify_datastore_plugin_interface 1.0.0-next.2 [amplify_core collection flutter meta]
- amplify_db_common 0.1.2 [amplify_db_common_dart drift flutter path path_provider]
- amplify_db_common_dart 0.1.3 [amplify_core async aws_common drift meta path sqlite3]
- amplify_flutter_android 1.0.0-next.2 [flutter]
- amplify_flutter_ios 1.0.0-next.2 [amplify_core flutter]
- amplify_secure_storage 0.1.4 [amplify_secure_storage_dart async file flutter meta path path_provider]
- amplify_secure_storage_dart 0.1.4 [async aws_common built_collection built_value ffi file js meta path win32 worker_bee]
- amplify_storage_s3_dart 0.1.4 [amplify_core amplify_db_common_dart async aws_common aws_signature_v4 built_collection built_value drift fixnum meta path smithy smithy_aws]
- archive 3.3.5 [crypto path pointycastle]
- args 2.3.1
- async 2.9.0 [collection meta]
- aws_common 0.3.5 [async built_collection built_value collection http2 js json_annotation logging meta mime os_detect path stream_transform uuid]
- aws_signature_v4 0.3.1 [async aws_common collection convert crypto json_annotation meta path]
- bloc 8.1.0 [meta]
- built_collection 5.1.1
- built_value 8.4.2 [built_collection collection fixnum meta]
- characters 1.2.1
- clock 1.1.1
- collection 1.16.0
- connectivity_plus 3.0.2 [flutter flutter_web_plugins connectivity_plus_platform_interface js meta nm]
- connectivity_plus_platform_interface 1.2.3 [flutter meta plugin_platform_interface]
- convert 3.1.1 [typed_data]
- crclib 3.0.0 [meta tuple]
- cross_file 0.3.3+2 [js meta]
- crypto 3.0.2 [typed_data]
- dbus 0.7.8 [args ffi meta xml]
- drift 2.3.0 [async convert collection js meta stream_channel sqlite3]
- ffi 2.0.1
- file 6.1.4 [meta path]
- fixnum 1.0.1
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- http 0.13.5 [async http_parser meta path]
- http2 2.0.1
- http_parser 4.0.2 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.5+4 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.10 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.6+4 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- intl 0.17.0 [clock path]
- js 0.6.4
- json_annotation 4.7.0 [meta]
- logging 1.1.0
- material_color_utilities 0.1.5
- meta 1.8.0
- mime 1.0.3
- nested 1.0.0 [flutter]
- nm 0.5.0 [dbus]
- oauth2 2.0.1 [collection crypto http http_parser]
- os_detect 2.0.1
- path 1.8.2
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.22 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.11 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32]
- petitparser 5.1.0 [meta]
- platform 3.1.0
- plugin_platform_interface 2.1.3 [meta]
- pointycastle 3.6.2 [collection convert js]
- process 4.2.4 [file path platform]
- provider 6.0.5 [collection flutter nested]
- retry 3.1.0
- shared_preferences_android 2.0.14 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.2 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.2 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.0 [async collection http_parser path stack_trace stream_channel]
- sky_engine 0.0.99
- smithy 0.3.2 [async aws_common built_collection built_value collection convert crypto fixnum http_parser intl json_annotation meta path retry shelf typed_data xml]
- smithy_aws 0.3.2 [aws_common aws_signature_v4 built_collection built_value collection convert crclib crypto intl json_annotation meta path smithy xml]
- source_span 1.9.0 [collection path term_glyph]
- sqlite3 1.9.1 [collection ffi js meta path]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.1.0
- string_scanner 1.1.1 [source_span]
- term_glyph 1.2.1
- tuple 2.0.1
- typed_data 1.3.1 [collection]
- uuid 3.0.7 [crypto]
- vector_math 2.1.2
- web_socket_channel 2.2.0 [async crypto stream_channel]
- webview_flutter_android 3.1.1 [flutter webview_flutter_platform_interface]
- webview_flutter_platform_interface 2.0.0 [flutter meta plugin_platform_interface]
- webview_flutter_wkwebview 3.0.1 [flutter path webview_flutter_platform_interface]
- win32 3.1.3 [ffi]
- worker_bee 0.1.3 [async aws_common built_collection built_value collection js meta path stack_trace stream_channel stream_transform]
- xdg_directories 0.2.0+2 [meta path process]
- xml 6.1.0 [collection meta petitparser]

Device

iPhone 12

OS

macOS 13.1

Deployment Method

Amplify CLI

CLI Version

10.5.2

Additional Context

No response

Amplify Config

{
    "features": {
        "graphqltransformer": {
            "addmissingownerfields": true,
            "improvepluralization": false,
            "validatetypenamereservedwords": true,
            "useexperimentalpipelinedtransformer": true,
            "enableiterativegsiupdates": true,
            "secondarykeyasgsi": true,
            "skipoverridemutationinputtypes": true,
            "transformerversion": 2,
            "suppressschemamigrationprompt": true,
            "securityenhancementnotification": false,
            "showfieldauthnotification": false,
            "usesubusernamefordefaultidentityclaim": true,
            "usefieldnameforprimarykeyconnectionfield": false,
            "enableautoindexquerynames": true,
            "respectprimarykeyattributesonconnectionfield": true,
            "shoulddeepmergedirectiveconfigdefaults": false,
            "populateownerfieldforstaticgroupauth": true
        },
        "frontend-ios": {
            "enablexcodeintegration": true
        },
        "auth": {
            "useenabledmfas": true
        },
        "codegen": {
            "useappsyncmodelgenplugin": true,
            "usedocsgeneratorplugin": true,
            "usetypesgeneratorplugin": true,
            "cleangeneratedmodelsdirectory": true,
            "retaincasestyle": true,
            "addtimestampfields": true,
            "handlelistnullabilitytransparently": true,
            "emitauthprovider": true,
            "generateindexrules": true,
            "enabledartnullsafety": true
        },
        "appsync": {
            "generategraphqlpermissions": true
        },
        "latestregionsupport": {
            "pinpoint": 1,
            "translate": 1,
            "transcribe": 1,
            "rekognition": 1,
            "textract": 1,
            "comprehend": 1
        },
        "project": {
            "overrides": true
        }
    },
    "debug": {
        "shareProjectConfig": false
    }
}
HuiSF commented 1 year ago

Hi @EricDunaway Thanks for reporting this issue, I did some digging in Amplify platform libraries, that the ModelOperation definition is consistent as enum ModelOperation { CREATE, UPDATE, DELETE, READ }. It looks libraries don't support the finer control over the detailed read operations.

Do you have any specific use case requires the finer control where using read is insufficient?

EricDunaway commented 1 year ago

@HuiSF I am trying to prevent the use of list operations from FE clients

The auth rule works as intended when querying the API in the console, but the generated code is causing build failures due to the missing values.

I suppose this could be considered a bug with the model generator, but since the generated code matches what I defined in the schema, I feel the library is incorrect.

HuiSF commented 1 year ago

OK thanks for the detail. I couldn't think of a reason why the finer read operation control is not supported in the library, I need to do some digging and get back to you.