Spring Boot GraphQL groupBy和orderBy无法正常工作

时间:2019-04-25 00:46:28

标签: sql spring-boot graphql sql-order-by

我想通过使用graphQL获得排名结果

上一个查询类似于

select * from view_user_account_point group by totalPoint, userId order by totalPoint

我想通过总分获得排名系统的结果, order by也用于编号。但是,我不会像使用group Byorder By那样进行查询。

schema{
query:Query
}


type Query{
    AllViewPoints:[ViewUserAccountPoint]
    ViewPointByUserId(userAccountPointUserId:Int) : [ViewUserAccountPoint]

    }



type ViewUserAccountPoint{
 rowNum:Long
 userAccountPointUserId:Int
 subjectId:Int
 point:Int
userAccountPointTypeId:Int
userAccountCreatedDate:String
userAccountPointStudyId:Int
userAccountUserName:String
userAccountOwnerId:Int
userAccountStatusId:Int
pointTypeId:Int
pointTypeName:String
pointTypeDescription:String
levelUserId:Int
levelLogTypeId:Int
registeredDate:String
levelTypeId:Int
levelTypeName:String
levelTypeDescription:String
userLevelTypeUserRoleId:Int
creationRightNum:Int
levelStartPoint:Int
levelEndPoint:Int
 levelTypeOwnerId:Int
studyName:String
studyStatusId:Int
userAccountRoleId:Int
userAccountRoleName:String
userAccountWalletUserId:Int
totalPoint:Int
steemitPoint:Int
lastUpdatedTimestamp:String

    }

Grapql.service

@Value("classpath:userAccountPoint.graphqls")
    Resource resource;

    private GraphQL graphQL;

    @Autowired
    private AllViewPointsDataFetcher allViewPointsDataFetcher;

    @Autowired
    private ViewPointByUserIdDataFetcher viewPointsByUserIdDataFetcher;

    //load schema at application start up
    @PostConstruct
    private void loadSchema() throws IOException {
        File schemaFile = resource.getFile();
        TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(schemaFile);
        RuntimeWiring wiring = buildRuntimeWiring();
        GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(typeRegistry, wiring);
        graphQL = GraphQL.newGraphQL(schema).build();
    }

    private RuntimeWiring buildRuntimeWiring() {
        return RuntimeWiring.newRuntimeWiring()
                .type("Query", typeWiring -> typeWiring
                        .dataFetcher("AllViewPoints", allViewPointsDataFetcher)
                        .dataFetcher("ViewPointByUserId", viewPointsByUserIdDataFetcher))

                .build();
    }

    public GraphQL getGraphQL() {
        return graphQL;
    }

GraphQL.controller

@RestController
@RequestMapping("/restapi/graphql")
public class GraphQLController {

    @Autowired
    GraphQLService graphQLService;

    @PostMapping
    public ResponseEntity<Object> getAllStudyComments(@RequestBody String query) {
        ExecutionResult executionResult = graphQLService.getGraphQL().execute(query);

        return new ResponseEntity<>(executionResult, HttpStatus.OK);
    }

此外,还有存储库。

在GraphQL中无法使用groupByorderBy排序进行查询吗? 如果可能的话,请让我知道该怎么做。

0 个答案:

没有答案