0

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.

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
  }
}
vijay
  • 609
  • 5
  • 9

1 Answers1

1

That's not how GraphQL works. 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. Directives are not related to fragments.

kaqqao
  • 12,984
  • 10
  • 64
  • 118
  • thanks @kaqqao my question is how can we get the fragments done using GraphQL SPQR, can you help me find the answer please. – vijay May 06 '20 at 06:07