Angular 使用图形QL放大如何查询相关对象

Angular 使用图形QL放大如何查询相关对象,angular,amazon-web-services,graphql,Angular,Amazon Web Services,Graphql,我正在学习如何使用Amplify部署AWS应用程序 我有一个关于使用graphql的关系的问题。我只是按照文档的教程进行操作。我在这里生成了关于博客和帖子的示例模式: 我想知道如何进行比“全部查找”更复杂的查询 具体来说:我可以找到所有这样的帖子: import { APIService } from '../API.service'; export class BlogComponent implements OnInit { constructor(private apiService:

我正在学习如何使用Amplify部署AWS应用程序

我有一个关于使用graphql的关系的问题。我只是按照文档的教程进行操作。我在这里生成了关于博客和帖子的示例模式:

我想知道如何进行比“全部查找”更复杂的查询

具体来说:我可以找到所有这样的帖子:

import { APIService } from '../API.service';

export class BlogComponent implements OnInit {

constructor(private apiService: APIService) { }

@Input()
blog: any;

posts: any;

ngOnInit() {
    this.apiService.ListPosts().then((evt) => {
      this.posts = evt.items;
    });
}
}
ngOnInit()函数中的代码可以列出所有帖子。但是我如何通过博客id找到帖子呢

graphhql模式如下所示,这只是上述链接中教程的一部分:

type Blog @model {
  id: ID!
  name: String!
  posts: [Post] @connection(name: "BlogPosts")
}
type Post @model {
  id: ID!
  title: String!
  blog: Blog @connection(name: "BlogPosts")
  comments: [Comment] @connection(name: "PostComments")
}

在生成的代码中,我看到了这些的crud操作,但没有看到“连接”的crud操作。如何找到某个博客的所有帖子?

我找到了。我有一个博客列表,但该列表中没有每个博客项目中的帖子

所以在“博客组件”中,我有一个博客,我想列出帖子,我必须按id查询博客(在博客列表中提供,查询由amplify预编译)。按id查询的博客包含已填充的帖子

@Component({
  selector: 'app-blog',
  templateUrl: './blog.component.html',
  styleUrls: ['./blog.component.css']
})
export class BlogComponent implements OnInit {

  @Input()
  blog: Blog;

  posts: Array<Post>;

  constructor(private apiService: APIService) {}

  ngOnInit() {

    this.apiService.GetBlog(this.blog.id).then((blog) => {
      this.posts = blog.posts.items;
    });

  }

}
@组件({
选择器:“应用程序博客”,
templateUrl:'./blog.component.html',
样式URL:['./blog.component.css']
})
导出类BlogComponent实现OnInit{
@输入()
博客:博客;
职位:阵列;
构造函数(私有apiService:apiService){}
恩戈尼尼特(){
this.apiService.GetBlog(this.blog.id).then((blog)=>{
this.posts=blog.posts.items;
});
}
}

我想出来了。我有一个博客列表,但该列表中没有每个博客项目中的帖子

所以在“博客组件”中,我有一个博客,我想列出帖子,我必须按id查询博客(在博客列表中提供,查询由amplify预编译)。按id查询的博客包含已填充的帖子

@Component({
  selector: 'app-blog',
  templateUrl: './blog.component.html',
  styleUrls: ['./blog.component.css']
})
export class BlogComponent implements OnInit {

  @Input()
  blog: Blog;

  posts: Array<Post>;

  constructor(private apiService: APIService) {}

  ngOnInit() {

    this.apiService.GetBlog(this.blog.id).then((blog) => {
      this.posts = blog.posts.items;
    });

  }

}
@组件({
选择器:“应用程序博客”,
templateUrl:'./blog.component.html',
样式URL:['./blog.component.css']
})
导出类BlogComponent实现OnInit{
@输入()
博客:博客;
职位:阵列;
构造函数(私有apiService:apiService){}
恩戈尼尼特(){
this.apiService.GetBlog(this.blog.id).then((blog)=>{
this.posts=blog.posts.items;
});
}
}