This is useful for acquiring the nodes that point to this Note node through a HAS_NOTE edge.
How can this behaviour be replicated in GraphQL? Is there any way to achieve links to multiple different types in only one predicate?
Hi @gorillastanley
Extending @abhijit-kar suggestion, we can define an interface that will help with the flexibility to achieve links to multiple types via one predicate.
For example:
Consider following schema:
Then we can have mutations in the following order:
Create Course
mutation {
addCourse(input: [{
name: "Welcome to Dgraph",
chapters: [
{
name: "Introduction to graphql",
data : "Graphql is Easy"
}
]
}]) {
course {
cId
}
}
}
Create Question
mutation {
addQuestion(input: [{
name: "Questions: Welcome to Dgraph",
questions: "Did you like it?",
answer: "yes"
}]) {
question {
cId
}
}
}
Create User
mutation {
addUser(input: [{
username: "XYZ",
email: "xyz@abc.com",
content: [
{
cId: "0x3" #check this id
},
{
cId: "0x5" #check this id
}
]
}]) {
user {
userId
username
Content {
cId
name
... on Course {
chapters {
name
data
}
}
... on Question {
questions
answer
}
}
}
}
}
Notice the return of the third mutation. content points to two different types i.e. Course and Question. Using @hasInverse directive you can manage two-way edges.