Given a graphql Query
query @my (arg:1) {
foo @my (arg:2) {
bar @my (arg:3)
foobar @my (arg:4)
}
}
And graphql server implementation using graphql-spqr
@GraphQLType(name="foo")
public class Foo{
@GraphQLQuery(name="bar")
public String bar;
@GraphQLQuery(name="foobar")
public String foobar;
}
@GraphQLDirective(name="my", locations = {QUERY, FIELD} )
public class MyGraphqlDirective{
@GraphqlInputField("arg")
public int arg;
}
public class GraphqlService{
@GraphQLQuery(name = "foo")
public Foo foo(@Nullable @GraphQLDirective(name="my") MyGraphqlDirective my){
Foo foo=new Foo();
if(my!=null){
foo.bar = String.valueOf(my.arg);
foo.foobar = String.valueOf(my.arg);
}
return foo;
}
}
I have access to (arg:2)
on the query foo, if it is exists, and fallback to (arg:1)
if that was absent.
However, I have problem if I would like to read that on field foo and foobar.
I'd want to, make it not readable, abusing @GraphqlContext
for every single field.
Is there any easier way to archive some simple logic (e.g. uppercase, locale, rounding, number format) on field level.
Also tried dataFetchingEnvironment.getSelectionSet().get().getSubField("edge/node/foo/bar").getSingleField().getDirective()
which doesn't take the Directive from parent