Spring boot 集成 Graphql


Spring boot 集成 Graphql

重要文件

root.graphqls

定義方法參數以及返回值

type Query{
    listTest(count: Int): [TestModel]
    allTest: [TestModel]
}
schema.graphqls

定義實體的結構

type TestModel{
    id: Int
    name: String
    version: String
    testTime: Long
    example: TestExampleModel
}

type TestExampleModel{
    id: Int
    name: String
    desc: String
}

代碼

Query

查詢相關的操作

  • 實現GraphQLQueryResolver
    對應root.graphqls當中查詢方法的定義
  • 實現GraphQLResolver<T>
    可以注入GraphQLQueryResolver返回結果的屬性中
Mutation

修改相關的操作


Schema

類型

  • type
  • enum
  • interface

注釋

"""
注釋
"""

描述

# 描述

描述可以顯示在graphiql的文檔中,方便查閱


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM