Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Change default resolveType to use User defined __resolveType when available #456

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hedonhermdev
Copy link

Fixes: #414
Aims to let user-defined resolvers for Interfaces and Queries work.

For example users can define a union like:

union SearchItem = Actor | Movie

And the resolver for this union:

const resolver = {
    SearchItem: {
        __resolveType(obj) => {
            return "TypeName"
        }
    }
}

@benjamin-rood
Copy link

benjamin-rood commented Jan 17, 2021

@hedonhermdev Hi, have you tested that this and confirmed that it works? I can't replicate.

To explain, if I do the following:

const resolver = {
    SearchItem: {
        __resolveType(obj) => {
            console.log('__resolveType for <SearchItem> called')
            return 'TypeName'
        }
    }
}

And the console.log line never prints.

But, if I do this instead:

const resolver = {
  Actor: {
    __isTypeOf: () => {
      console.log('called __isTypeOf function for <Actor>') // gets printed
      return 'Actor';
    }
  },

  Movie: {
    __isTypeOf: () => {
      console.log('called __isTypeOf function for <Movie>') // gets printed
      return 'Movie'
    }
  },
}

@michaeldgraham
Copy link
Collaborator

#608

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

Successfully merging this pull request may close these issues.

Can't query interface types
4 participants