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

Custom primary key is not supported by the GraphQL helper #2061

Closed
2 of 13 tasks
a9udn9u opened this issue Aug 24, 2022 · 2 comments
Closed
2 of 13 tasks

Custom primary key is not supported by the GraphQL helper #2061

a9udn9u opened this issue Aug 24, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists feature-request A request for a new feature or an enhancement to an existing API or category. GraphQL API Issues related to the API (GraphQL) Category

Comments

@a9udn9u
Copy link

a9udn9u commented Aug 24, 2022

Description

I'm migrating an Amplify JavaScript project to Amplify Flutter, a few of my GraphQL models look like this:

type Foo @model
@auth(
  rules: [
    ...
  ]
)
{
  key: ID! @primaryKey
  value: String!
}

Everything worked well in the JS project. I did an amplify pull in the new Flutter project, the GraphQL schema file was correctly pulled down, then I ran amplify codegen models, a Foo.dart is created, which looks like this:

@immutable
class Foo extends Model {
  static const classType = const _FooModelType();
  final String id;
  final String? _key;
  final String? _value;
  final TemporalDateTime? _createdAt;
  final TemporalDateTime? _updatedAt;

  @override
  getInstanceType() => classType;
  
  @override
  String getId() {
    return id;
  }
......

My code for querying data from the Foo table:

    final req = ModelQueries.list(Foo.classType, where: Foo.KEY.eq('some-key'));
    final resp = await Amplify.API.query(req)).response;

I always get a validation error. "Validation error of type FieldUndefined: Field 'id' in type 'Foo' is undefined @ 'listFoo/items/id'". Why does codegen generate a model file that doesn't match the actual GraphQL model?

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Storage

Steps to Reproduce

See description.

Screenshots

No response

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Android Device/Emulator API Level

No response

Environment

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.5 21G72 darwin-arm, locale en-US)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Community Edition (version 2022.1.3)
[✓] VS Code (version 1.70.1)
[✓] VS Code (version 1.71.0-insider)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

! Doctor found issues in 2 categories.

Dependencies

$ flutter pub deps --no-dev --style=compact
Dart SDK 2.17.6
Flutter SDK 3.0.5
hanyuan 1.0.0+1

dependencies:
- amplify_api 0.6.6 [amplify_api_android amplify_api_ios amplify_core amplify_flutter aws_common collection flutter meta plugin_platform_interface]
- amplify_auth_cognito 0.6.6 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_flutter 0.6.6 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- cupertino_icons 1.0.5
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]

transitive dependencies:
- amplify_api_android 0.6.6 [flutter]
- amplify_api_ios 0.6.6 [amplify_core flutter]
- amplify_auth_cognito_android 0.6.6 [flutter]
- amplify_auth_cognito_ios 0.6.6 [amplify_core flutter]
- amplify_core 0.6.6 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.6 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.6 [flutter]
- amplify_flutter_ios 0.6.6 [amplify_core flutter]
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.16.0
- crypto 3.0.2 [typed_data]
- http 0.13.5 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- json_annotation 4.6.0 [meta]
- material_color_utilities 0.1.4
- meta 1.7.0
- path 1.8.1
- plugin_platform_interface 2.1.2 [meta]
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2

Device

N/A

OS

iOS 15.5

Deployment Method

Custom Pipeline

CLI Version

9.2.1

Additional Context

No response

Amplify Config

Not sure how to get this..

@HuiSF HuiSF added GraphQL API Issues related to the API (GraphQL) Category pending-triage This issue is in the backlog of issues to triage labels Aug 24, 2022
@HuiSF
Copy link
Member

HuiSF commented Aug 24, 2022

Hi @a9udn9u thanks for opening this issue.

Your model schema requires support of custom primary key (CPK).

  • amplify-flutter library now contains support of CPK for only the DataStore plugin
  • Amplify CLI (and Amplify Codegen) support of CPK is now pending release
  • amplify-flutter library API plugin GraphQL helper support of CPK is planed but has not been implemented

Therefore, at this moment, amplify codegen cannot generate correct model for model schema that uses @primaryKey. Which causes the inconsistency you are seeing.

When Amplify CLI (and Amplify Codegen) support of CPK gets released, the codegen will generate correct model according to @primaryKey directive. However, the GraphQL helper of amplify-flutter won't work with CPK, where you need to compose the GraphQL document manually.

And we will work on making the GraphQL helper work with CPK soon, please stay tuned. Thanks!

@HuiSF HuiSF added feature-request A request for a new feature or an enhancement to an existing API or category. and removed pending-triage This issue is in the backlog of issues to triage labels Aug 24, 2022
@HuiSF HuiSF changed the title Is a field named "id" required in all GraphQL models? Custom primary key is not supported by the GraphQL helper Aug 24, 2022
@HuiSF HuiSF added the duplicate This issue or pull request already exists label Aug 24, 2022
@HuiSF
Copy link
Member

HuiSF commented Aug 24, 2022

I'm closing this issue in favor of this feature request issue
#1426

We will update the progress on the linked, please feel free to follow up and provide feedback and suggestions. Thanks!

@HuiSF HuiSF closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists feature-request A request for a new feature or an enhancement to an existing API or category. GraphQL API Issues related to the API (GraphQL) Category
Projects
None yet
Development

No branches or pull requests

2 participants