We know how to create a link between objects.
unlink function removes a link between two objects. The link can be a one-to-one reference or a one-to-many reference.
Let’s see how to use the unlink
function.
We will use the same schema from the previous post.
type OldObject {
field1: String
}
type NewObject {
fld1: String
fld2: OldObject
fld3: [OldObject]
}
-
unlink
function has the below signature.
unlink(
from:HypiMutationType!
to:HypiMutationType!
via:String!
whereFromID:String!
andToID:String!
):Boolean!
-
from
andto
fields indicate the data types to remove a link -
via
is the field of data type ‘to’ in the data type ‘from’ -
whereFromID
andandToID
are the hypi.id of the objects to be unlinked.
Sample Query
Now we will unlink the objects using the unlink
function
mutation {
unlink(
from: NewObject
to: OldObject
via: "fld2"
whereFromID: "01FHZM6G4P3N7AARH85755VX0X"
andToID: "01FHZM11Q6MG3NKVR8D14QGKFH"
)
}
#result
{
"data": {
"unlink": true
}
}
Output
The function returns true
if the unlinking is successful otherwise false
.
Query with Variables
mutation unlinkObjects(
$from: HypiMutationType!
$to: HypiMutationType!
$via: String!
$whereFromID: String!
$andToID: String!
) {
unlink(
from: $from
to: $to
via: $via
whereFromID: $whereFromID
andToID: $andToID
)
}
#query variables
{
"from": "NewObject",
"to": "OldObject",
"via": "fld3",
"whereFromID": "01FHZM6G4P3N7AARH85755VX0X",
"andToID": "01FHZM11Q9C03SJK1XM9SK603R"
}
Check the POSTMAN collection for the unlink
requests in different programming languages! Click </>
and choose the programming language of your choice.
Don’t forget to insert your own Authorization key and Hypi Domain under Headers to test the results!