Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 Boot_Graphql_Graphql Spqr_Graphql Spring Boot - Fatal编程技术网

如何为java联合生成graphql模式?

如何为java联合生成graphql模式?,java,spring-boot,graphql,graphql-spqr,graphql-spring-boot,Java,Spring Boot,Graphql,Graphql Spqr,Graphql Spring Boot,我的团队正计划使用阿波罗网关作为联盟。因此,我们需要以稍微不同的方式生成模式 我们能用你的神奇库制作出这样的东西吗 extend type User @key(fields: "id") { id: ID! @external reviews: [Review] } 是否要向类型添加一些字段和指令 您可以使用@GraphQLContext将外部方法附加为字段。或者甚至提供一个自定义的ResolverBuilder,它返回额外的Resolvers(这些稍后会映射到字段)。 要添加指令,您

我的团队正计划使用阿波罗网关作为联盟。因此,我们需要以稍微不同的方式生成模式

我们能用你的神奇库制作出这样的东西吗

extend type User @key(fields: "id") {
  id: ID! @external
  reviews: [Review]
}

是否要向类型添加一些字段和指令

您可以使用
@GraphQLContext
将外部方法附加为字段。或者甚至提供一个自定义的
ResolverBuilder
,它返回额外的
Resolver
s(这些稍后会映射到字段)。 要添加指令,您可以创建带有
@graphqldirection
元注释的注释(示例请参见测试)。 最后,您当然可以为
用户
提供自定义
类型映射器
,并完全控制该类型的映射方式

例如,您可以制作如下注释:

@GraphQLDirective(locations = OBJECT)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Key {
    public String[] fields;
}
如果随后将此注释放置在类型上:

@Key(fields = "id")
public class User {
    @External //another custom annotation
    public @GraphQLId @GraphQLNonNull String getId() {...}
}
它将被映射为:

type User @key(fields: "id") {
    id: ID! @external
}
我想你知道
@GraphQLContext
,但简而言之:

//Some service class registered with GraphQLSchemaBuilder
@GraphQLApi
public class UserService {

    @GraphQLQuery
    public List<Review> getReviews(@GraphQLContext User user) {
        return ...; //somehow get the review for this user
    }
}
//向GraphQLSchemaBuilder注册的某个服务类
@GraphQLApi
公共类用户服务{
@图形查询
公共列表getReviews(@GraphQLContext User){
return…;//以某种方式获取此用户的审阅
}
}

由于
@GraphQLContext
,类型
User
现在有一个
review:[review]
字段(即使
User
类没有该字段)。

谢谢!但它似乎不起作用。请看