且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Apollo GraphQL生成Java客户端?

更新时间: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

  • 使用以下build.gradle创建Java项目
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'
}