title: Retrieve all connected objects and array of objects in a single query
body: <p>I'm having trouble in bringing nested array of objects from a single query generated by AWS Amplify CLI. I can see I get a single nested object from a single query, but not an array of objects.</p>
  <p>I would be highly glad for any of your inputs.</p>
  <p>The functionality I want: I have a Model named Post which contains, among others, a list of Comments. I would like to retrieve all posts along with all comments associated with the posts, by not supplying the postId, so esentiially I would like to have a query like getPosts({limit: 50}).</p>
  <p>The issue: I don't get the Comments for Posts from the query that I'm issuing. I see a single object, like User, properly returned from the query. In fact, in the query that is generated by Amplify, I see the following query generated for the post model:</p>
  <pre><code>comments {
           nextToken
         }
  </code></pre>
  <p><strong>I am unable to get a query generated for Post with all the fields from the nested Comment model.</strong></p>
  <p>I followed the discussion at <a href="https://stackoverflow.com/questions/63716173/one-to-many-relationship-not-showing-in-the-object-amplify-schema-definition">One to Many Relationship not showing in the object Amplify Schema definition</a>. But, unfortunately I've not been able to get the result I want.</p>
  <p>I went through a few documentations for AWS Amplify, AppSync on the AWS site, but seem unable to fix the issue.</p>
  <p>One note - I can see that if I fetch the Comments, I see the parent Post which has this Comment.</p>
  <p>I'm sharing the GraphQL schema that I've:</p>
  <pre><code>
  type Post
    @model
    @auth(rules: [{ allow: owner, operations: [create, read, update, delete], identityField: &quot;sub&quot; }])
    @key(
      name: &quot;byTime&quot;
      fields: [&quot;type&quot;, &quot;createdAt&quot;, &quot;updatedAt&quot;]
      queryField: &quot;getPosts&quot;
    )
    @key(
      name: &quot;byUser&quot;
      fields: [&quot;type&quot;, &quot;userId&quot;]
      queryField: &quot;getPostsByUser&quot;
    ) {
    type: TableName!
    id: ID!
    userId: String
    user: User! @connection(name: &quot;UserPost&quot;)
    createdAt: AWSDateTime!
    updatedAt: AWSDateTime!
    title: String
    content: String
    files: [S3Object]
    comments: [Comment!]
      @connection(
        keyName: &quot;byPostId&quot;
        fields: [&quot;id&quot;, &quot;updatedAt&quot;]
        name: &quot;PostComments&quot;
      )
    likes: [User]
    likeCount: String
  }
  
  type Comment
    @model
    @auth(rules: [{ allow: owner, operations: [create, read, update, delete], identityField: &quot;sub&quot; }])
    @key(
      name: &quot;byTime&quot;
      fields: [&quot;type&quot;, &quot;createdAt&quot;, &quot;updatedAt&quot;]
      queryField: &quot;getComments&quot;
    )
    @key(
      name: &quot;byPostId&quot;
      fields: [&quot;postId&quot;, &quot;updatedAt&quot;]
      queryField: &quot;getCommentsByPostId&quot;
    ){
    type: TableName!
    id: ID!
    postId: ID!
    userId: String
    content: String
    createdAt: AWSDateTime!
    updatedAt: AWSDateTime!
    post: Post @connection(fields: [&quot;postId&quot;])
    likes: [User]
    likeCount: String
    user: User @connection
  }
  
  enum TableName {
    User
    Profile
    Post
    Comment
  }
  
  type User
    @model
    @key(
      name: &quot;byUserEmail&quot;
      fields: [&quot;type&quot;, &quot;email&quot;]
      queryField: &quot;getUserByEmail&quot;
    )
    
    @auth(
      rules: [
        { allow: owner, operations: [read, create, delete, update], identityField: &quot;sub&quot; }
      ]
    ) {
    id: ID!
    type: TableName!
    name: String!
    email: ID!
    createdAt: String
    profile: Profile @connection(name: &quot;UserProfile&quot;)
    profileCreated: Boolean
    posts: [Post] @connection(name: &quot;UserPost&quot;)
  }
  
  type Profile
    @model
    @key(
      name: &quot;byUserId&quot;
      fields: [&quot;type&quot;, &quot;userId&quot;]
      queryField: &quot;getProfileByUserId&quot;
    )
    @key(
      name: &quot;byUserEmail&quot;
      fields: [&quot;type&quot;, &quot;userEmail&quot;]
      queryField: &quot;getProfileByUserEmail&quot;
    )
     @auth(
      rules: [
        { allow: owner, operations: [create, read, update, delete], identityField: &quot;sub&quot; }
      ]
    ) {
    id: ID!
    type: TableName!
    userId: ID!
    role: Role!
    classRoom: String
    ... other fields
    user: User @connection(name: &quot;UserProfile&quot;)
  }
  
  enum Role {
    TeachingStaff
    Student
    NonTeachingStaff
    Alumni
  }
  
  type S3Object {
    bucket: String! 
    region: String! 
    key: String! 
  }
  
  
  </code></pre>
  <p>Thank you in advance.</p>