Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

Nesting resolvers for client state data #255

Open
vegetablesalad opened this issue May 28, 2018 · 6 comments
Open

Nesting resolvers for client state data #255

vegetablesalad opened this issue May 28, 2018 · 6 comments
Assignees

Comments

@vegetablesalad
Copy link

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?

@jsslai
Copy link

jsslai commented May 29, 2018

It should be resolvers: { Query: ... } instead of resolvers: { Queries: ... }

@vegetablesalad
Copy link
Author

vegetablesalad commented May 29, 2018

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

@hwillson
Copy link
Member

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!

@jasonbahl
Copy link

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?

@fletcherist
Copy link

Any updates?

@anwilson514
Copy link

Any updates on this?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants