简体   繁体   English

如何使用 spring-spqr graphql-spqr-spring-boot-starter graphQL 的注释创建片段

[英]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-startergraphql-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.

相关问题 我们如何从 GraphQL 的 RequestContextHolder 中获取 GraphQL 的 HttpServletRequest(DefaultGlobalContext)(使用 graphql-spqr-spring-boot-starter)? - How can we get HttpServletRequest(DefaultGlobalContext) for GraphQL from RequestContextHolder for GraphQL (using graphql-spqr-spring-boot-starter)? 为什么我会收到与使用 graphql-spqr-spring-boot-starter 的“类型名称冲突”相关的警告? - Why am I getting a warning related to 'type name collision' using graphql-spqr-spring-boot-starter? 如何使用 spqr-spring-boot-starter 在 graphql 中获取模式文件? - How to get a schema file in graphql using spqr-spring-boot-starter? 带有 Spring Boot 和事务边界的 graphql-spqr - graphql-spqr with Spring Boot and Transactional Boundary SPQR GraphQL中的持久查询 - Persisted queries in SPQR GraphQL ValidationError FieldUndefined SPQR GraphQL - ValidationError FieldUndefined SPQR GraphQL 如何使用SPQR和Spring注册ResolverInterceptors - How to register ResolverInterceptors with SPQR and Spring spring boot starter graphql无法正常工作 - spring boot starter graphql not working 如何配置 GraphQL SPQR 以使用 Gson 而不是 Jackson - How to configure GraphQL SPQR to use Gson instead of Jackson GraphQL SPQR扩展输入对象的变异参数 - GraphQL SPQR extend mutation parameters of an input object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM