Amplify-cli: TypeError: Cannot read property 'type' of undefined

Created on 12 May 2020  路  7Comments  路  Source: aws-amplify/amplify-cli

Hello,

I have updated the schema.graphql file and I am trying to complie it but I am getting the following error:

TypeError: Cannot read property 'type' of undefined

I am trying to implement many-to-many using two 1-M @connections, an @key, and a joining @model as explained here:

Below is my schema:

type User @model {
  email: String!
  firstName: String!
  lastName: String!
  isJobSeeker: Boolean
  age: Int
  mobile: String
  address: String
  userJobList: [UserJobs] @connection(keyName: "byUserJobs", fields: ["email"] )
}

type UserJobs 
  @model(queries: null)
  @key(name: "byUserJobs", fields:["emailID", "jobsID"])
  @key(name: "byJob", fields:["jobsID", "emailID"]) {
    id:ID!
    emailID: String!
    jobsID: String!
    user: User! @connection(fields: ["emailID"])
    job: Job! @connection(fields: ["jobsID"])
}

type Job @model {
    jobID: String!
    isVolunteerJob: Boolean!
    orgName: String
    jobType: String
    startDate: String
    endDate: String
    noOfHours: Int
    startTime: String
    endTime: String
    description: String
    amount: Int
    address: String
    userList: [UserJobs] @connection(keyName: "byJob", fields: ["jobID"])
}
graphql-transformer question

Most helpful comment

Closing this issue as the PR for this has been merged and will be included in the next release (after v4.24.1)

All 7 comments

I'm getting the same warning and can't seem to track down where it's coming from... I only get:

[0] Reloading failed with error
[0] TypeError: Cannot read property 'type' of undefined

@loganpowell Could you please share your schema? What's the version of the CLI you're using?

@zerox92 What version of the CLI are you using?

sure thing @kaustavghosh06

amplify cli version: 4.18.0

schema:


# 
# access patterns -> schema:
# 1:N = bulletin  => links
# N:1 = bulletins => campaign
# 1:1 = bulletin  => detail
# N:N = topics    => bulletins // see: https://youtu.be/eUQvsuO6EnU?t=1200
# 

type Topic @model{
  id                           : ID!
  code                         : String
  bulletins                    : [BulletinTopic]  @connection (keyName: "byTopic", fields: ["id"])
  name                         : String           # 'Foreign Trade Standard Data Products'
  description                  : String           # 'Training opportunities'
}


type Campaign @model {
  id                           : ID!          # "20190312rcsiss2ccpuprs"
  # each bulletin can 'belong to' one campaign
  bulletins                    : [Bulletin]       @connection (keyName: "byCampaign", fields: ["id"])
}


type Bulletin
  @model
  @key(name: "byCampaign", fields: ["campaign_id", "created_at"])
{
  bulletin_id                  : ID!
  campaign_id                  : ID!          # "20190312rcsiss2ccpuprs"
  campaign                     : Campaign         @connection (fields: ["campaign_id"])
  created_at                   : AWSDateTime
  detail                       : BulletinDetail 
  links                        : [Link]           
  topics                       : [BulletinTopic]  @connection (keyName: "byBulletin", fields: ["bulletin_id"])
}

# enable N:N relationship via a ref

type BulletinTopic 
  @model (queries: null)                          # ?? ... disable queries ...??
  @key(name: "byBulletin", fields: ["bulletin_id", "topic_id"])
  @key(name: "byTopic",    fields: ["topic_id", "bulletin_id"]) 
{
  id                           : ID!
  bulletin_id                  : ID!
  topic_id                     : ID!
  topic                        : Topic!           @connection (fields: ["topic_id"])
  bulletin                     : Bulletin!        @connection (fields: ["bulletin_id"])
  created_at                   : AWSDateTime
  subscriptions_this_period    : SubsReport       
  subscriptions_to_date        : SubsReport       
}


type SubsReport {
  total_subscriptions          : Int
  new_subscriptions            : Int
  deleted_subscriptions        : Int
  bulletins_sent               : Int
  allocation                   : Allocation
}

type Allocation { 
  direct                       : Int
  overlay                      : Int
  signup                       : Int
  upload                       : Int
  other                        : Int
  all_network                  : Int
}

type BulletinDetail {
  created_at                   : AWSDateTime      # "2019-03-12T18:30:11.000Z"
  subject                      : String           # "Here's What You Missed Statistics In Schools"
  to_text                      : String           # "Subscribers of Administrators, Education Organizations, ..."
  delivery_status_name         : String           # "Delivered"
  addresses_count              : Int              # 48965
  success_count                : Int              # 45992
  failed_count                 : Int              # 2973
  percent_success              : Float            # 93.928316144184621669
  immediate_email_recipients   : Int              # 48965
  emails_delivered             : Int              # 45992
  emails_failed                : Int              # 2973
  percent_emails_delivered     : Float            # 93.928316144184621669
  opens_count                  : Int              # 696
  percent_opened               : Float            # 1.513306662028178814
  nonunique_opens_count        : Int              # 891
  links_count                  : Int              # 18
  click_rate                   : Float            # 0.19786049747782223
  clicks_count                 : Int              # 91
  nonunique_clicks_count       : Int              # 119
  sender_email                 : AWSEmail         # "[email protected]"
  digest_email_recipients      : Int              # 0
  #------------------- BUBBLED -------------------#
  unique_click_count           : Int              # 97
  total_click_count            : Int              # 126
  unsubscribes                 : Int              # 19
  # bubble up further to Bulletin -> campaign      : Campaign         # "20190312rcsiss2ccpuprs"
}

type Link {
  id                           : ID!          # "123245322"
  link_url                     : AWSURL           # "https://bl.ow/utm_campaign=2019rs...govdelivery"
  unique_click_count           : Int              # 1
  total_click_count            : Int              # 2
}


# DAILY SUBSCRIBER SUMMARY REPORT #

type SubsSummary @model {
  # inject per day
  id                           : ID!
  created_at                   : AWSDate          # "2019-03-12"
  direct_subscribers           : Int              # 521     
  direct_subscriptions         : Int              # 7015    
  overlay_subscribers          : Int              # 277     
  overlay_subscriptions        : Int              # 292     
  signup_subscribers           : Int              # 0       
  signup_subscriptions         : Int              # 0       
  upload_subscribers           : Int              # 9761    
  upload_subscriptions         : Int              # 13220   (combine with diff on future topic bulletins)
  other_subscribers            : Int              # 0       
  other_subscriptions          : Int              # 0       
  total_subscribers            : Int              # 1350491 (cumulative)
  total_subscriptions          : Int              # 6175151 (cumulative)
  deleted_subscribers          : Int              # 3274    
  deleted_subscriptions        : Int              # 30442   
  all_network_subscribers      : Int              # 3843    
  all_network_subscriptions    : Int              # 31902   
  net_subscribers              : Int              # 11128   
  net_subscriptions            : Int              # 21987   
}

Ok, I got it working. I suppose there is some constraint I wasn't aware of regarding unique fields with the many:many trick. I'm not sure, but the following change compiles:

...

type Bulletin
  @model
  @key(name: "byCampaign", fields: ["campaign_id", "created_at"])
{
-  bulletin_id  : ID!
+  id           : ID!
  campaign_id   : ID!          
  campaign      : Campaign         @connection (fields: ["campaign_id"])
  created_at    : AWSDateTime
  detail        : BulletinDetail 
  links         : [Link]           
- topics        : [BulletinTopic]  @connection (keyName: "byBulletin", fields: ["bulletin_id"])
+ topics        : [BulletinTopic]  @connection (keyName: "byBulletin", fields: ["id"])
}

type BulletinTopic 
  @model (queries: null)                       
  @key(name: "byBulletin", fields: ["bulletin_id", "topic_id"])
  @key(name: "byTopic",    fields: ["topic_id", "bulletin_id"]) 
{
  id            : ID!
  bulletin_id   : ID!  # <- DUPLICATED FIELD SEEMS TO BREAK COMPILATION
  topic_id      : ID!
  topic         : Topic!           @connection (fields: ["topic_id"])
  bulletin      : Bulletin!        @connection (fields: ["bulletin_id"])
...    
}
...

Thank you for the quick response though! 鉂わ笍 鉂わ笍 鉂わ笍 the work you guys are doing.

Using this reference from the docs

type Project @model {
  id: ID!
  name: String
  teamID: ID!
  team: Team @connection(fields: ["teamID"])
}

type Team @model {
  id: ID!
  name: String!
}

teamID is used as the value to reference Team, if no keyName is specified it will default to the primary key in Team, which is ID, since that field does not exist it will error out with TypeError.
@zerox92
Both fields with connections are looking for id in the User and Job which are not defined. Adding the fields (as @loganpowell mentioned) should get it to work.

user: User! @connection(fields: ["emailID"])
job: Job! @connection(fields: ["jobsID"])

As a takeaway we can add some error checking around this to avoid confusion.

I've gotten this error with malformed m2m connections as well. The current documentation is probably sufficient but the error message should really be improved, took me a while to figure out where my mistake was.

Closing this issue as the PR for this has been merged and will be included in the next release (after v4.24.1)

Was this page helpful?
0 / 5 - 0 ratings