Generated input model is empty
See original GitHub issueHi, I’m having trouble understanding how to use SPQR. I’ve use a similar project for node https://typegraphql.ml/docs/introduction.html before with much success, which shares a lot of concepts with this.
Questions:
~1. How to correctly generate input types for object classes?~
~2. How to control the required tribute of a schema object of field, eg (stockSize: Long!
)?~
3. How can I generate a schema minus the extra annotations for use with a client or for documentation?
~4. @GraphQLId
does not produce a schema field that uses the type ID
?~
~5. How would I exclude a generated field like Id
from an input type but not the output type, does this require multiple classes?~
Simple example
Dependency versions:
Java: 1.8
spring-boot-starter-parent: 2.1.1.RELEASE
io.leangen.graphql.spqr: 0.9.9
Here we have a simple POJO User.java
@Data // lombok
public class User {
private final @GraphQLId Integer id;
private String email;
private final String username;
private String phoneNumber;
private final Boolean isActive;
}
And a resolver that references the user in a query and a mutation UserResolver.java
@Component
public class UserResolver {
private UserService userService;
@Autowired
UserResolver(
UserService userService
) {
this.userService = userService;
}
@GraphQLQuery(name = "getUsers")
public ArrayList<User> getUsers(){
return this.userService.getUsers();
}
@GraphQLMutation(name = "createUser")
public User createUser(@GraphQLArgument(name = "User") User user){
return this.userService.creatUser(user);
}
}
When the schema is rendered with new SchemaPrinter().print(schema);
I get the following
#Mutation root
type Mutation {
createUser(User: UserInput): User @_mappedOperation(operation : "__internal__")
}
#Query root
type Query {
getUsers: [User] @_mappedOperation(operation : "__internal__")
}
type User @_mappedType(type : "__internal__") {
email: String @_mappedOperation(operation : "__internal__")
id: Int @_mappedOperation(operation : "__internal__")
isActive: Boolean @_mappedOperation(operation : "__internal__")
phoneNumber: String @_mappedOperation(operation : "__internal__")
username: String @_mappedOperation(operation : "__internal__")
}
input UserInput @_mappedType(type : "__internal__") {
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top GitHub Comments
Worth trying:
… to annotate the generated getter rather than the instance variable itself. Lombok doesn’t copy annotations from vars to generated methods.
Using
@Setter(onMethod = @__({@GraphQLIgnore}))
is experamental so ill stick with writing the getters and setter myself. For futre reference.Model
Resolver
will result in the types