apollo-link-state
apollo-link-state copied to clipboard
Nesting resolvers for client state data
How can I add local resolvers to fetch data from client state if scheme is nested ?
schema {
query: RootQuery
mutation: RootMutation
}
type RootQuery {
profile: Profile
}
type Profile {
guid: String!
user(idProviderName: String): User
users: [User]
}
I'm trying this to define resolver, but with no luck:
const stateLink = withClientState({
cache,
resolvers: {
Queries: {
Profile:{
user:(_:any, data:any, { cache }:any):User=>{
return null;
}
}
}
}
});
What is the correct way of doing this?
It should be resolvers: { Query: ... } instead of resolvers: { Queries: ... }
So that would look like this?
const stateLink = withClientState({
cache,
resolvers: {
Mutation:{
...
},
Query:{
Profile:{
user: ():any => {
...
}
}
}
},
defaults: {
profile:{
__typename: "Profile",
user:{
__typename: "User",
guid:"0"
}
}
},
});
I get result from defaults, but the user() function is never called
Any chance you can provide a small runnable reproduction that shows what you're trying and isn't working? There are a few important details missing here that will help with troubleshooting (like what the query you're trying looks like, etc.). Thanks!
I’m having the same issue. When working with Apollo Server graphql-rolls is used to make an executable Schema which allows you to define resolvers for each Type in the Schema so nested fields that resolve to another Type just pass their data down to the resolver for said type.
It seems as though link-state only is aware of the top-level resolvers and doesn’t have an easy way to define a resolver for a Type that is nested in the Schema.
It would be sweet if link-state made use of graphql-tools allowing for nested Type resolvers to easily be defined.
Perhaps there’s already a way to do this that I’m just missing through?
Any updates?
Any updates on this?