GraphQL实战
1.1.根据需求编写GraphQL文件
在resources目录下新建.graphqls
文件
schema {
query: HaokeQuery
}
type HaokeQuery {
HouseResources(id:Long) : HouseResources
HouseResourcesList(page:Int, pageSize:Int) : TableResult
IndexAdList:IndexAdResult
}
type HouseResources {
id:Long!
title:String
estateId:Long
buildingNum:String
buildingUnit:String
buildingFloorNum:String
rent:Int
rentMethod:Int
paymentMethod:Int
houseType:String
coveredArea:String
useArea:String
floor:String
orientation:String
decoration:Int
facilities:String
pic:String
houseDesc:String
contact:String
mobile:String
time:Int
propertyCost:String
}
type TableResult{
list:[HouseResources]
pagination:Pagination
}
type Pagination{
current:Int
pageSize:Int
total:Int
}
type IndexAdResult{
list:[IndexAdResultData]
}
type IndexAdResultData{
original:String
}
1.2.将GraphQL对象注入到Spring容器中
package org.fechin.haoke.dubbo.api.graphql;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import org.fechin.haoke.dubbo.api.service.HouseResourcesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileNotFoundException;
/**
* @Author: