Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中具有复杂对象的Graphql_Java_Spring_Graphql_Graphql Java - Fatal编程技术网

java中具有复杂对象的Graphql

java中具有复杂对象的Graphql,java,spring,graphql,graphql-java,Java,Spring,Graphql,Graphql Java,我在谷歌和stackoverflow上搜索了很多。大多数示例来自spring boot。我是springboot的新手。我对如何使用graphql获取数据感到非常困惑。 在下面的示例中,我有一个报告组,其中可以包含多个报告 如何获取组的详细信息以及自定义报告详细信息 我应该使用什么?解析程序/数据获取程序 如果是解析器,请帮助我进行适当的解释 结果应该是: { group{ name : xyz reports [ { id:

我在谷歌和stackoverflow上搜索了很多。大多数示例来自spring boot。我是springboot的新手。我对如何使用graphql获取数据感到非常困惑。 在下面的示例中,我有一个报告组,其中可以包含多个报告

如何获取组的详细信息以及自定义报告详细信息

我应该使用什么?解析程序/数据获取程序

如果是解析器,请帮助我进行适当的解释

结果应该是:

{
    group{
       name : xyz
       reports [
       {
          id:7
          name : report1
       },
       {
         id:8
         name : report2
       },
       {
         id:9
         name : report3
       }
      ]
  }    
}

报表组类

模式:

数据获取程序


您还需要定义您的客户群数据。 试试下面的方法

  schema {
        query: Query
    }
    type CustomReport{
    id:Int!,
    name:String!

    }
    type Query {
        reportgroup:ReportGroup
    }

    type ReportGroup{
        name:String!,
         customReport : [CustomReport]
    }

您还需要定义您的客户群数据。 试试下面的方法

  schema {
        query: Query
    }
    type CustomReport{
    id:Int!,
    name:String!

    }
    type Query {
        reportgroup:ReportGroup
    }

    type ReportGroup{
        name:String!,
         customReport : [CustomReport]
    }
@Transactional(readOnly = true)
    public ReportGroup getReportGroupDetail(final Integer id){
return this.reportGroupDAO
                .findById(id);

}
schema {
    query: Query
}
type Query {
    reportgroup:ReportGroup
}

type ReportGroup{
    name:String!,
     customReport : [CustomReport]
}
public class ReportGroupDataFetcher implements DataFetcher<ReportGroup> {

@Autowired
ReportGroupService reportGroupService;

@Override
public Group get(final DataFetchingEnvironment env) {   
    Group   group = this.reportGroupService.getReportGroupDetail(1);        
    return group;
}

}
@RequestMapping(value = "/secure/getGroupDetail", method = RequestMethod.POST)
    public ResponseBody<Object> getGroupDetail(     
            @RequestBody final JsonData jsonData,
            final HttpServletRequest request)  {
        final JSONObject jsonRequest = new JSONObject(jsonData.getData());  
        final GraphQL graphQL = this.schemaBuilder.getGraphQL();        
        final ExecutionInput executionInput = ExecutionInput.newExecutionInput()
                .query(jsonRequest.getString("query")).build();     
        final ExecutionResult executionResult = graphQL.execute(executionInput);        
        return new ResponseBody(executionResult, Constants.SUCCESS);
    }
public class SchemaBuilder {
@Autowired
ReportGroupDataFetcher reportgroupDataFetcher;


public GraphQL getGraphQL() {
    final SchemaParser schemaParser = new SchemaParser();
    final SchemaGenerator schemaGenerator = new SchemaGenerator();
    final File schemaFile = new File(myFileName);
    final TypeDefinitionRegistry typeRegistry = schemaParser
            .parse(schemaFile);
    final RuntimeWiring wiring = buildRuntimeWiring();
    final GraphQLSchema graphQLSchema = schemaGenerator
            .makeExecutableSchema(typeRegistry, wiring);
    return GraphQL.newGraphQL(graphQLSchema).build();
}

private RuntimeWiring buildRuntimeWiring() {
    return RuntimeWiring.newRuntimeWiring().type("Query",
            typeWiring -> typeWiring                        
                    .dataFetcher("reportgroup", this.reportgroupDataFetcher))               
            .build();
    }


 }
  schema {
        query: Query
    }
    type CustomReport{
    id:Int!,
    name:String!

    }
    type Query {
        reportgroup:ReportGroup
    }

    type ReportGroup{
        name:String!,
         customReport : [CustomReport]
    }