Skip to content

Conversation

@danez
Copy link
Contributor

@danez danez commented Aug 31, 2020

I have the following use case:

const CarSchema = new Schema({ s: { type: Number, required: true, alias: "speed" } }, { discriminatorKey: 't' });
const Car = model('Car', CarSchema);

const TimeMachineSchema = new Schema({ f: { type: Number, required: true, alias: "fluxCompensatorVersion" } }, { discriminatorKey: 't' });
const TimeMachine = Car.discriminator('TimeMachine', TimeMachineSchema);

...

const CarDTC = composeWithMongooseDiscriminators(Car);

schemaComposer.Query.addFields({
  allCars: CarDTC.getResolver("findMany"),
});

...


gql`
{
  query FindAllCars() {
    allCars() {
      __typename
      speed

      ... on TimeMachine {
        fluxCompensatorVersion
      }
    }
  }
}
`

So we create a resolver from the base DTC which should be able to resolve all its discriminator documents.

The query does not work and errors with

Cannot return null for non-nullable field TimeMachine.fluxCompensatorVersion.

The reason is that in this example for Car the lib does not consider the aliases of all its discriminators, so it does not translate the alias for TimeMachine in this example.

Let me know what you think.

@nodkz nodkz merged commit aaa59a7 into graphql-compose:master Aug 31, 2020
@nodkz
Copy link
Member

nodkz commented Aug 31, 2020

I think it's great! 👍
Thanks a lot for this fix! 🙏

@github-actions
Copy link

🎉 This PR is included in version 8.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 9.0.0-alpha.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@danez danez deleted the patch-1 branch September 14, 2020 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants