Is there any way to backfill @hasInverse directive

Hey All,

Is there a way for me to backfill the @hasInverse directive? I’m trying to evolve my schema from requirements, so I ended up adding the @hasInverse later, when I needed it. However, this has caused my queries to break.

Simplest Example Below:
Initial Schema

type Collection {
  name: String!
  entries: [Entry]!
}

type Entry {
  value: Float!
}

Schema later

type Collection {
  name: String!
  entries: [Entry]!
}

type Entry {
  value: Float!
  collection: Collection! @hasInverse(field: entries)
}

The following query will start to bonk, as existing entries do not have the link from entry -> collection

{
  queryEntry {
    value
    collection { name }
  }
}

Is there some way to backfill this data so that I can continue to use the same interface? I guess we have ± support, so maybe that would work?

3 Likes

± support is only for queries ATM. No mutation support at present.

This is a genuine problem, if someone is just using GraphQL APIs. We will have to think about if we should offer users a chance to backfill the data in such cases at schema update time.

Nevertheless, you could do some ± magic at /mutate. You would need to set the value of Entry.collection predicate for all existing Entry nodes to the uid of their respective Collection nodes.

2 Likes

cool, I also stumbled upon this same issue…
@abhimanyusinghgaur could you please post a sample of ± magic /mutate that suits @gja 's schema change example ?
I hope there will be in future some automatic backfilling on schema change !

@aleclofabbro the idea is to basically update the relations with subsequent mutations. So for the above sample schema, we can have mutations like this (this is rdf format):

{
	set {
           <0x2> <Entry.collection> <0x3> .
          .... more triples
       }
}
}

In this way all the past data will be backfilled and available for queries.

1 Like