0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

リゾルバとは

0
Posted at

リゾルバとは

GraphQLでこのデータをくださいとリクエストが来た時、実際に取ってくる処理のこと


{
 user:(id:1){
	name
		posts {
			title
		}
	 }
}

バックエンド側で「userを取ってくる処理」「postsを取ってくる処理」をそれぞれ書く必要がある。これがリゾルバ:

const resolvers = {
  // user(id: 1) が来たらDBからユーザーを探す
  user: (args) => {
    return db.users.find(u => u.id === args.id);
  },
  // そのユーザーのpostsが来たら投稿を探す
  posts: (parent) => {
    return db.posts.filter(p => p.user_id === parent.id);
  },
};

GraphQLを導入すると、フィールドごとにこのリゾルバを書く必要がある。データが少ないアプリでこれをやるのは手間に対してメリットが薄い。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?