Closed austinarbor closed 1 year ago
Not really sure where you got the above quote from, but it definitely was not from SPQR. In fact, there is no such annotation as @Argument
in SPQR. I think you're confusing Spring GraphQL with SPQR's SpringBoot Starter.
Anyway, in SPQR, there are multiple ways to customize everything about the generated schema, but here's the most direct approach:
@GraphQLNonNull
to make the argument non-nullable (i.e. required)@GraphQLArgument(defaultValue = "...")
to add a default valueE.g.
@GraphQLQuery
// BookId is be required
public Book findBook(@GraphQLNonNull BookId id) {
return ...;
}
Or
@GraphQLQuery
// Non-null list of non-null IDs is required
public List<Book> findBooks(@GraphQLNonNull List<@GraphQLNonNull BookId> id) {
return ...;
}
Or
@GraphQLQuery
// Default value specified
public List<Book> findByTag(@GraphQLArgument(name = "tag", defaultValue = "popular") String tag) {
return ...;
}
Or
@GraphQLQuery
// The given default value is an object
public Book echo(@GraphQLArgument(name = "in", defaultValue = "{\"title\":\"Funky Monkey\"}") Book in) {
return in;
}
@kaqqao @GraphQLNonNull
cannot be used with @GraphQLArgument
, which loses the name and description of the field.
@kaqqao you're right, I meant to open this ticket on the spring-graphql project and I have no idea how I opened it up on this project instead, sorry about that! Thanks for answering anyways!
@StringKe I haven't had any problem using @GraphQLNonNull
together with @GraphQLArgument
in multiple projects
@kaqqao
@GraphQLNonNull
cannot be used with@GraphQLArgument
, which loses the name and description of the field.
No clue what you mean. You can definitely use those annotations together. But whenever someone is complaining about annotations not working or other bizarre behavior, it's because of Lombok.
@kaqqao
When I look at the source code the setting here is not ElementType.PARATMER.
When I give @GraphQLArgument(description="test") @ElementType java.lang.String name
it doesn't work.
import io.leangen.graphql.annotations.GraphQLSubscription;
import io.leangen.graphql.annotations.GraphQLMutation;
import io.leangen.graphql.annotations.GraphQLQuery;
import io.leangen.graphql.annotations.GraphQLArgument;
import io.leangen.graphql.annotations.GraphQLNonNull;
public class GenerateResult {
@GraphQLQuery(name = "user")
public com.txys.service.system.pojo.vo.SystemUserVO method0currentSystemUserInfo(
) {
return null;
}
@GraphQLMutation(name = "logout")
public java.lang.Boolean method1logout(
) {
return null;
}
@GraphQLMutation(name = "login")
public com.txys.service.system.pojo.vo.SystemUserVO method2login(
@GraphQLArgument(name = "username", description = "username") java.lang.String username,
@GraphQLArgument(name = "password", description = "password") java.lang.String password
) {
return null;
}
@GraphQLQuery(name = "testPermission")
public java.lang.String method3testPermission(
@GraphQLArgument(name = "checkLogin", description = "checkLogin") java.lang.Boolean checkLogin,
@GraphQLArgument(name = "checkRole", description = "checkRole") java.lang.Boolean checkRole,
@GraphQLArgument(name = "checkPermission", description = "checkPermission") java.lang.Boolean checkPermission
) {
return null;
}
@GraphQLMutation(name = "kickSystemUser")
public java.lang.Boolean method4kickSystemUser(
@GraphQLArgument(name = "account", description = "account") java.lang.String account,
@GraphQLArgument(name = "device", description = "device") java.lang.String device
) {
return null;
}
@GraphQLMutation(name = "addSystemUser")
public com.txys.service.system.pojo.vo.SystemUserVO method5addSystemUser(
@GraphQLArgument(name = "dto", description = "dto") com.txys.service.system.pojo.dto.SystemUserDTO dto
) {
return null;
}
@GraphQLQuery(name = "findSystemUser")
public org.springframework.data.domain.Page<com.txys.service.system.pojo.vo.SystemUserVO> method6searchSystemUser(
@GraphQLArgument(name = "username", description = "username") java.lang.String username,
@GraphQLArgument(name = "searchRequest", description = "searchRequest") com.txys.commom.core.jpa.SearchRequest searchRequest
) {
return null;
}
@GraphQLMutation(name = "addSystemMenu")
public com.txys.service.system.pojo.vo.SystemMenuVO method7addSystemUser(
@GraphQLArgument(name = "dto", description = "dto") com.txys.service.system.pojo.dto.SystemMenuDTO dto
) {
return null;
}
@GraphQLQuery(name = "findSystemMenu")
public org.springframework.data.domain.Page<com.txys.service.system.pojo.vo.SystemMenuVO> method8searchSystemUser(
@GraphQLArgument(name = "searchRequest", description = "searchRequest") com.txys.commom.core.jpa.SearchRequest searchRequest
) {
return null;
}
}
If I write import statements for all types there is no problem.
Hello, Can you please add examples of how to make an input argument required and how to specify a default value for them? The documentation has a tip
However I can't find any further documentation or examples in the repo or in the graphql-java guides on how to do this programmatically.
Ideally we'd just be "decorating" the existing schema rather than having to specify the entire schema via file