neo4j-graphql-js icon indicating copy to clipboard operation
neo4j-graphql-js copied to clipboard

Change default resolveType to use User defined __resolveType when available

Open hedonhermdev opened this issue 5 years ago • 2 comments

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"
        }
    }
}

hedonhermdev avatar Jun 17 '20 18:06 hedonhermdev

@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'
    }
  },
}

benjamin-rood avatar Jan 17 '21 20:01 benjamin-rood

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608

michaeldgraham avatar May 02 '21 04:05 michaeldgraham