参考URL
- 下記のページを参考にstrapiでgraphqlを利用できるようにしてみる
strapi.io
インストール
- strapiのプロジェクトフォルダ内で下記のコマンドを実行して、graphqlのパッケージをインストールする
yarn strapi install graphql
動作確認
queryの仕様
単一の場合
- 単一のレコードを取得する場合、idの指定が必須らしい
query {
address(id: 1){
id
post_code
prefectures
city_name
town_name
}
article(id: 1){
id
title
}
}
複数のデータを取得し、かつWhere句で絞り込みしたい場合のクエリー
query getAddresses ($postCode: String!, $title: String!){
addresses(where: { post_code: $postCode } ) {
id
post_code
prefectures
city_name
town_name
}
articles(where: { title: $title }){
id
title
}
}
{
"postCode": "1010048",
"title": "件名"
}
データ更新の場合
mutation {
createArticle(input: { data: { title: "テスト", details: "詳細です"} }){
article {
id
title
details
}
}
}