[英]how to create fragments using Annotations of spring-spqr graphql-spqr-spring-boot-starter graphQL
using graphql-spqr-spring-boot-starter and graphql-spqr but not able to create Fragment using @GraphQLDirective, not sure if there is anyway to do it.使用graphql-spqr-spring-boot-starter和graphql-spqr但无法使用 @GraphQLDirective 创建片段,不确定是否有办法这样做。
my intension is to create Fragment through code like我的意图是通过像这样的代码来创建片段
@Data
@GraphQLFragment
public class ProfileFields{
private String name;
private String emailId;
private String phoneNo;
}
and use this fragment in the query below, can someone guide me what are the annotations used for this并在下面的查询中使用这个片段,有人可以指导我使用的注释是什么
{
profile(id: "101"){
...ProfileFields
}
}
That's not how GraphQL works.这不是 GraphQL 的工作方式。 Fragments are defined by the client ad-hoc.
片段由客户端临时定义。 You can not define them ahead of time on the server.
您不能在服务器上提前定义它们。 The definition of the fragment is a part of the query.
片段的定义是查询的一部分。 There's nothing you need to (or can) do on the server for the fragments to work.
您无需(或可以)在服务器上执行任何操作以使片段正常工作。
The client could send a query such as:客户端可以发送查询,例如:
{
profile(id: "101") {
... ProfileFields
}
}
fragment ProfileFields on Profile {
name
registrationDate
}
As for @GraphQLDirective
, it is used to define schema (server-side) directives.至于
@GraphQLDirective
,它用于定义模式(服务器端)指令。 Directives are not related to fragments.指令与片段无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.