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

DataStore - Nested types are not supported #260

Closed
kjones opened this issue Dec 17, 2020 · 16 comments
Closed

DataStore - Nested types are not supported #260

kjones opened this issue Dec 17, 2020 · 16 comments
Assignees
Labels
Android Issues specific to the Android Platform Codegen Issues related to Amplify code generation datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category. iOS Issues specific to the iOS Platform

Comments

@kjones
Copy link

kjones commented Dec 17, 2020

An example would be the following:

type TestModel @model {
  id: ID!
  nested: NestedType!
  listOfNested: [NestedType!]!
}

type NestedType {
  field1: Int!
  field2: String!
}

This schema currently results in a SubSelectionRequired response error from AppSync when establishing subscriptions.

@Ashish-Nanda Ashish-Nanda added the feature-request A request for a new feature or an enhancement to an existing API or category. label Dec 18, 2020
@raywhiteside
Copy link

raywhiteside commented Jan 2, 2021

To expound upon a major aspect of the issue here, I'm not seeing NestedType have a class generated for it. While the NestedType is not defined as a @model, it does cause a NestedType.dart file to be generated in lib/models. However this is the entirety of the generated file:

/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
*  http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart';
import 'package:flutter/foundation.dart';

Not even a constructor is generated. This class seems to be correctly referenced in the generated TestModel.dart, though the class is imported in neither TestModel.dart nor ModelProvider.dart (the latter of which may be correct as NestedType is not a @model).

I'm a bit confused how the OP got to an AppSync response error in this case, as the code generation issues I describe lead to compile errors. Perhaps my issue isn't quite the same, but does seem to be related to custom nested types.

Additionally I think it's fair to tag this more strongly than a feature request, as I seem to be generating code that doesn't compile from a successful run of amplify codegen models. I suspect this feature will be accepted and added, but otherwise codegen should throw an error.

@kjones
Copy link
Author

kjones commented Jan 2, 2021

There are a bunch of problems with the Amplify CLI when generating Flutter models so to produce the SubSelectionRequired error, I was experimenting with rolling my own definitions for the nested types. While doing that I discovered that nested type support in the Flutter model schema definitions was left out on purpose.

Furthermore, I found that it doesn't look like the Android SerializedModel schema definition selection set generation code supports nested types. Nested types in native Android Java models appears to work fine.

For reference:
Android SerializedModel schema definition selection set generation
Android Java model selection set generation
iOS selection set generation

Agree that this should be marked with a little more urgency than a feature request. Flutter DataStore support at this point is pretty much useless for anything other than trivial @model schemas due to various problems with CLI codegen, Android, and Flutter SDKs. I'm hoping the DataStore feature gets a revisit and some much needed ❤️ soon.

@rlee1990
Copy link

I too have this same issue when trying to use codegen and using the S3Object example with graphql schema

@kjones
Copy link
Author

kjones commented Feb 19, 2021

I would like to request that this issue be turned into a bug instead of a feature request in hopes of elevating its priority.

Nested types are supported on all other platforms and without this support I am still resorting to using my own custom DataStore plugin for Flutter (described here) I created back in September.

Do you know of any workarounds or hacks that would let me switch to the official DataStore Flutter SDK plugin when the backend GraphQL schema is already in use by other platforms? I thought I might be able to just switch the local schema to use AWSJSON as the field type, generate the Flutter models, and then deserialize these nested types myself. However, that doesn't work because the backend AppSync requests/sync/subscriptions are expecting a specific format and I get the SubSelectionRequired error mentioned in previous comments.

@fjnoyp fjnoyp self-assigned this Mar 3, 2021
@fjnoyp fjnoyp added Android Issues specific to the Android Platform bug Something is not working; the issue has reproducible steps and has been reproduced datastore Issues related to the DataStore Category investigating iOS Issues specific to the iOS Platform labels Mar 3, 2021
@fjnoyp
Copy link
Contributor

fjnoyp commented Mar 3, 2021

Hi guys thank you all for explaining the issue encountered. @kjones we will mark this as a bug as well and investigate this more on our side.

@fjnoyp fjnoyp added the Codegen Issues related to Amplify code generation label Mar 3, 2021
@kjones kjones changed the title Question: DataStore - Are custom nested types supported? DataStore - Nested types are not supported Mar 13, 2021
@Alexminator99
Copy link

I got the same problem now. Awesome!!!

type S3Object {
bucket: String!
region: String!
key: String!
}

type DocumentPicture @model (...) {
id: ID!
name: String
owner: String
timestamp: AWSDate
file: S3Object!
}

It only generates the licence header and import 2 .dart archives. Thats it for S3Object. Is there is a workaround?

Im in latest version -> 4.48.0.

@lfraker
Copy link

lfraker commented Jun 7, 2021

Running into the same issue. Are there any updates on the investigation/fix?

@HuiSF HuiSF assigned HuiSF and unassigned fjnoyp Jul 6, 2021
@HuiSF HuiSF removed bug Something is not working; the issue has reproducible steps and has been reproduced investigating labels Aug 5, 2021
@hackrx
Copy link

hackrx commented Aug 7, 2021

I am also facing the same issue, any updates on this?

@ChaitanyaVootla
Copy link

ChaitanyaVootla commented Aug 12, 2021

I'm unable to create and use any 1:n relationship, which is a very basic use case, can someone please tell me if there is a workaround

@HuiSF
Copy link
Member

HuiSF commented Aug 31, 2021

Hi @ChaitanyaVootla sorry for missing your comment above. I wanted to follow up with the use case you mentioned.

I'm unable to create and use any 1:n relationship

What are you actually referring to by 1:n relationship?

e.g. 1:n (hasMany relationship) this is supported by amplify-flutter DataStore today.

type Post @model {
  id: ID!
  title: String!
  comments: [Comment] @connection(keyName: "byPost", fields: ["id"])
}

type Comment @model
  @key(name: "byPost", fields: ["postID", "content"]) {
  id: ID!
  postID: ID!
  content: String!
}

Or are you referring to collection of a CustomType? (this feature is in progress) e.g.

type Album @model {
  id: ID!
  name: String!
  pictures: [S3Object]
}

type S3Object {
  bucket: String!
  region: String!
  key: String!
}

@offlineprogrammer offlineprogrammer removed the feature-request A request for a new feature or an enhancement to an existing API or category. label Sep 2, 2021
@Ashish-Nanda Ashish-Nanda added the feature-request A request for a new feature or an enhancement to an existing API or category. label Oct 15, 2021
@HuiSF
Copy link
Member

HuiSF commented Nov 8, 2021

Hi all, amplify-flutter 0.3.0-rc.2 has been release which includes the support of CustomType.

This preview release requires a corresponding preview release of @aws-amplify/cli. Please refer to the changelog to get the detail how to start using CustomType with this preview release. Please test with your project, and follow up if you encounter any issues. Feedback is much appreciated!

@Ashish-Nanda
Copy link
Contributor

Ashish-Nanda commented Nov 16, 2021

@kjones @raywhiteside Were you able to give the preview release a try?

@raywhiteside
Copy link

I have not, sorry.

@kjones
Copy link
Author

kjones commented Nov 16, 2021

I have not had a chance to try this either and probably won't be able to get to this for a few weeks.

@djorgji
Copy link

djorgji commented Dec 23, 2021

Done a bit of preliminary testing with 0.3.0-rc.3 and 7.7.0-flutter-preview.1 it seems to be working, still need to do a bit more testing, but so far so good.

@HuiSF
Copy link
Member

HuiSF commented Jan 20, 2022

CustomType is now supported with version 0.3.0. Thanks everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues specific to the Android Platform Codegen Issues related to Amplify code generation datastore Issues related to the DataStore Category feature-request A request for a new feature or an enhancement to an existing API or category. iOS Issues specific to the iOS Platform
Projects
None yet
Development

No branches or pull requests