nexus icon indicating copy to clipboard operation
nexus copied to clipboard

Interface resolveType is not optional

Open Sytten opened this issue 4 years ago • 7 comments

It should be possible to define:

export const UserError = interfaceType({
  definition(t) {
    t.string('id')
  },
  name: 'UserError',
})

But I get an error:

Argument of type '{ definition(t: InterfaceDefinitionBlock<"UserError">): void; name: "UserError"; }' is not assignable to parameter of type 'NexusInterfaceTypeConfig<"UserError">'.
  Property 'resolveType' is missing in type '{ definition(t: InterfaceDefinitionBlock<"UserError">): void; name: "UserError"; }' but required in type '{ resolveType: AbstractTypeResolver<"UserError">; }'

Sytten avatar Feb 09 '21 22:02 Sytten

It should be possible to define:

Are you using https://nexusjs.org/docs/guides/abstract-types#centralized-strategy-resolvetype?

Then this is expected I think.

jasonkuhrt avatar Feb 09 '21 23:02 jasonkuhrt

I mean the definition is:

Optionally provide a custom type resolver function. If one is not provided, the default implementation will first look for __typename, then fallback to calling isTypeOf on each implementing Object type.

I want to use the default implementation in this case :)

Sytten avatar Feb 09 '21 23:02 Sytten

Yeah something seems fishy here.

jasonkuhrt avatar Feb 10 '21 03:02 jasonkuhrt

Optionally provide a custom type resolver function. If one is not provided, the default implementation will first look for __typename, then fallback to calling isTypeOf on each implementing Object type.

Yeah I think this doc might have been from before we switched resolveType to be the default.

At the moment, I believe resolveType is required if __typename isn't explicitly defined on all sourceType for members of the interface.

I feel like the local abstract settings would be really helpful here. @jasonkuhrt have you given much thought on how difficult you think this might be?

tgriesser avatar Feb 11 '21 16:02 tgriesser

I feel like the local abstract settings would be really helpful here. @jasonkuhrt have you given much thought on how difficult you think this might be?

No thoughts up to now! And no sense on level-of-interest others have for it. Great to hear you think it would be useful. Have you heard any input from others about it too?

jasonkuhrt avatar Feb 11 '21 18:02 jasonkuhrt

I'm getting this error now and wondering what the correct fix for it is. Does anyone have one?

evanmcd avatar Oct 07 '21 16:10 evanmcd

Well, I seem to have found it pretty quickly after all. Adding this to the config object of makeSchema()

features: {
      abstractTypeStrategies: {
        resolveType: false
      }     
    }

evanmcd avatar Oct 07 '21 17:10 evanmcd