Amplify-cli: Datastore model generation to allow sub-types that are not @models

Created on 7 Dec 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

Is your feature request related to a problem? Please describe.
I have a data structure that has nested types.

enum LearnType {
  page
  link
  heading
  question
  note
}

type ExampleDoc
  @model
{
  id: ID!
  learn: [Learn]
}

type LearnItem {
  title: String
  text: String
  pageId: String
  content: String
  url: String
  question: String
  answer: String
  schemaVersion: String!
}

type Learn {
  seq: Int
  type: LearnType
  item: LearnItem
  schemaVersion: String!
}

I only have 1 DynamoDB table for the ExampleDocs, the learn items would then just be nested. This works as expected with using the GraphQL clients.

When I try to generated the model definition for the Datastore, I see the following error:

Error: Unknown type Learn for field learn. Did you forget to add the @model directive

Describe the solution you'd like
I would like the model generator to allow nested types that are not @models

Describe alternatives you've considered
Open to ideas

Most helpful comment

It seems that object with @model directive cannot contain any objects or list of objects that are not a model too.

Example:

type Stop {
    locationExternalCode: String!
    locationName: String!
}

type Job @model {
  stops: [Stop]
}

will fail, but if @model is removed or if both are models it works

All 4 comments

normally type Learn would appear at the top of the schema document, before it is referenced.

It seems that object with @model directive cannot contain any objects or list of objects that are not a model too.

Example:

type Stop {
    locationExternalCode: String!
    locationName: String!
}

type Job @model {
  stops: [Stop]
}

will fail, but if @model is removed or if both are models it works

My case has Geolocation that is passed to ElasticSearch as a Geopoint - so without support for this then any geospatial applications are unsupported.

type Geolocation { lat: Float lon: Float }

Tracking this request as a part of #2988
Closing this as a duplicate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ffxsam picture ffxsam  路  3Comments

davo301 picture davo301  路  3Comments

jeanpaulcozzatti picture jeanpaulcozzatti  路  3Comments

ReidWeb picture ReidWeb  路  3Comments

onlybakam picture onlybakam  路  3Comments