更新时间:2022-05-28 21:27:36
服务器设置
使用GraphQL Server进行Spring Boot: https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/
Spring Boot with GraphQL Server: https://www.graphql-java.com/tutorials/getting-started-with-spring-boot/
完整的GraphQL服务器代码可在GitHub上找到: https://github.com/graphql-java/tutorials/tree/master/book-details
Full working GraphQL server code exist on GitHub: https://github.com/graphql-java/tutorials/tree/master/book-details
客户
从架构生成GraphQL查询代码
Generate GraphQL Query Code from schema
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.apollographql.apollo:apollo-gradle-plugin:0.5.0'
}
}
plugins {
id 'java'
}
apply plugin: 'com.apollographql.android'
group = 'com.graphql-java.tutorial'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
dependencies {
compile group: 'com.apollographql.apollo', name: 'apollo-runtime', version: '0.5.0'
}
Download schema.jsonfromthe GraphQL server endpoint Go to CLI, run below command, it will generate schema.json
阿波罗服务:下载--endpoint = http://localhost:8080/graphql
将 schema.json 放入 main/graphql
运行Gradle构建任务,它将在 Build/generation/source/apollo 中生成客户端查询代码,其包结构与 BookById.graphql
Run Gradle build task it will generate Client Query Code in Build/generated/source/apollo with same package structure as of BookById.graphql
BookByIdQuery.java
BookByIdQuery.java
参考:
服务器GraphQL-Java: https://www.graphql-java.com/documentation/master/
Server GraphQL-Java : https://www.graphql-java.com/documentation/master/
Apollo客户端: https://www.apollographql.com/docs/android/essentials/get-started.html
Apollo Client: https://www.apollographql.com/docs/android/essentials/get-started.html
带有GraphQL查询示例的Spring Boot |技术入门手册: https://youtu.be/zX2I7-aIldE
Spring Boot with GraphQL Query Example | Tech Primers: https://youtu.be/zX2I7-aIldE
使用GraphQL和Spring构建数据API"-新加坡API Craft: https://youtu.be/GmR2uIDZEyM
"Building a data API with GraphQL and Spring" - API Craft Singapore: https://youtu.be/GmR2uIDZEyM