Adding types with interfaces using RDF triples in DQL

Hi, I currently have a schema simplified like so:

type User  {
  username: String! @id @search(by: [hash])
  items: [Item] @hasInverse(field: createdby)
}

interface Item {
  id: ID!
  title: String! @search(by: [exact])
  createdby: User!
}
    
type Folder implements Item {
    id: ID!
    title: String! @search(by: [exact])
    createdby: User!
    featured_image: String
}

I’m trying to add in a Folder with the following but it doesn’t work. I can see in data studio it creates an ID on the User.items edge but doesn’t have any data inside it.

<0x275f> <User.items> _:f1 .
 _:f1 <dgraph.type> "Folder" .
_:f1 <Folder.title> "test" .
_:f1 <Folder.createdby> <0x275f> .
_:f1 <Folder.featured_image> "test" .
1 Like

Update your schema to the following. It is not Schema compliant with GraphQL, but it is schema compliant with DGraph GraphQL schema input

type User  {
  username: String! @id @search(by: [hash])
  items: [Item] @hasInverse(field: createdby)
}

interface Item {
  id: ID!
  title: String! @search(by: [exact])
  createdby: User!
}
    
type Folder implements Item {
  featured_image: String
}

Then use:

<0x275f> <User.items> _:f1 .
 _:f1 <dgraph.type> "Folder" .
_:f1 <Item.title> "test" .
_:f1 <Item.createdby> <0x275f> .
_:f1 <Folder.featured_image> "test" .

And I believe that the dgraph.type should even have both "Folder" and "Item" in it. I am not sure that exact syntax though, either:

 _:f1 <dgraph.type> "Folder" "Item" .

or

 _:f1 <dgraph.type> "Folder" .
 _:f1 <dgraph.type> "Item" .

1 Like

Thanks, seems all good.