You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Splitting root query and mutation across many classes #35
Sorry if this is already possible, but would it be an option to have the root query and mutation objects split across many classes?
As best I can tell at present, these are only one single class, so if you have a large number of query fields - as a reasonable size API will - then they all end up in the same class. Worse though, this one class has many different concerns to worry about.
For example, the Query class on a blog might have to support: Users, Posts, Comments, and several different query methods for each of these.
@rolandkozma there isn't an example right now, but you can just implement GraphQLQueryResolver on any class you want to be scanned for root resolver methods.
All works correctly. But i want to split my resolvers in more classes according to the model entities:
UserResolver.java:
@Component
public class UserResolver implements GraphQLQueryResolver, GraphQLMutationResolver {
public User getUser(...) { ... }
public Product createUser(...) { ... }
}
ProductResolver.java:
@Component
public class ProductResolver implements GraphQLQueryResolver, GraphQLMutationResolver {
public Product getProducts(...) { ... }
public Product createProducts(...) { ... }
}
Caused by: com.coxautodev.graphql.tools.FieldResolverError: No method or field found with any of the following signatures (with or without one of [interface graphql.schema.DataFetchingEnvironment] as the last argument), in priority order:
...graphql.resolvers.SmartGroupsResolver.getUsers()
Activity
apottere commentedon Jul 10, 2017
This seems like a great idea, and it shouldn't be too hard to implement. Thanks for the suggestion!
apottere commentedon Jul 11, 2017
Duplicated by #32
Implement field datafetchers and multiple root resolvers (fixes #35, f…
rolandkozma commentedon Sep 6, 2017
Hi. Is there a sample of how to split the root query class across many resolver classes?
apottere commentedon Sep 6, 2017
@rolandkozma there isn't an example right now, but you can just implement
GraphQLQueryResolveron any class you want to be scanned for root resolver methods.rolandkozma commentedon Sep 6, 2017
That's nice! It works well. Initially I expected to have to split them in graphql schema too.
Thanks for answering!
santiago-vl commentedon Jun 5, 2018
@rolandkozma In my schema.graphql file i have this:
I have a RootResolver like this:
In the schema creation:
All works correctly. But i want to split my resolvers in more classes according to the model entities:
UserResolver.java:
ProductResolver.java:
Application.java:
If i do this i obtain the next error:
What am i doing wrong?
pclnzwang commentedon Jun 21, 2018
@SantyVylla Remove schema in the schema.graphqls file and try again. Defined resolvers based on "type Query / Mutation" is fine.