Inverse relation on GraphQL schema - Union Types

I need to use both GraphQL schema and apply RDF @reverse directive on some fields. The issue is that if the GraphQL schema is reapplied, reverse relations on those fields get deleted.

I see a way to get around it by modifying GraphQL schema fields with @dgraph directive, as described in 7336; however, it is not currently possible to use this solution on union types. Example:

<Object.owner>: uid @reverse .
type Object {
   owner: Person @dgraph(pred: "Object.owner")

type BusinessMan {
  companyName: String
  owns: [Object] @dgraph(pred: "~Object.owner")

type AnotherPersonType {
  owns: [Object] @dgraph(pred: "~Object.owner")

union Person = BusinessMan | AnotherPersonType

This errors:

couldn't rewrite mutation updateGQLSchema because input:1: Type Object; Field owner: should be of type BusinessMan to be compatible with @dgraph reverse directive but is of type Person.\n

I see that the same issue but with interfaces has been fixed; would it be possible to also allow such dgraph directives on union types?

Hi @Mariia_Stepaniuk
I already created an issue for that:

And looks like there is no straight forward solution right now. I solved my problem by creating a file:

curl -X POST localhost:8080/admin/schema --data-binary '@schema.graphql'
curl -X POST localhost:8080/alter -d   '<Object.owner>: [uid] @reverse .'

Thank you Poorshad!
Yes, making it possible to not override @reverse after GraphQL schema is applied would be ideal. Your solution (applying DQL migration each time after GraphQL runs) is very similar to the workaround we’re currently using, but it has some of its own issues.

1 Like

That’s true and it is just a short term remedy. Each time we are applying new schema it reindexes some data that should not be reindexed.

1 Like