iT邦幫忙

2025 iThome 鐵人賽

DAY 28
0
自我挑戰組

打造自己的Medium系列 第 28

Day28 HotChocolate

  • 分享至 

  • xImage
  •  

我也不懂為什麼GraphQL套件叫這個名字,ChilliCream的命名品味?
還有Client端的叫Strawberry Shake

操作類型

  • Queries(查詢):用於唯讀地取得資料
  • Mutations(突變):用來新增、刪除或更新資料
  • Subscriptions(訂閱):用於實時監聽系統中發生的事件與通知

查詢簡易範例

  1. 安裝指令
    dotnet add package HotChocolate.AspNetCore

  2. 定義QueryType

{
    public class Query
    {
        public string Hello() => "Hello from GraphQL Web API!";
    }
}
  1. 在Program.cs加入
builder.Services
    .AddGraphQLServer()
    .AddQueryType<Query>();
 
// 如果有其他endpoint,要在app.MapControllers()之前
app.MapGraphQL();
  1. 跑起來
    https://ithelp.ithome.com.tw/upload/images/20250901/20177994i94Iks1kJi.png
    https://ithelp.ithome.com.tw/upload/images/20250901/20177994GWrBWN0MMf.png

參考資料

Introduction

作者的哈拉

九月了/images/emoticon/emoticon61.gif


上一篇
Day27 GraphQL
下一篇
Day29 MongoDB Migration
系列文
打造自己的Medium29
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言