Skip to content

Instantly share code, notes, and snippets.

@christianwish
Last active July 5, 2018 08:18
Show Gist options
  • Save christianwish/e579769afc64260e8e5220f9e1fac2a7 to your computer and use it in GitHub Desktop.
Save christianwish/e579769afc64260e8e5220f9e1fac2a7 to your computer and use it in GitHub Desktop.
graphql relation mutation
# Step 1
# To create a B you have to create a A first
mutation {
createA(
title: "first A!"
) {
id
}
}
# Step 2
# Create a B with a relation to A
mutation makeBOrAnotherCoolFuncName ($aid: ID, $bTitle: String!) {
createB(
title: $bTitle
asId: $aid
) {
id
}
}
# Variables:
# {
# "aid": "ID_OF_AN_A",
# "bTitle": "My first B"
# }
type A @model {
id: ID! @isUnique
title: String
createdAt: DateTime!
bs: [B!]! @relation(name: "C")
}
type B @model {
id: ID! @isUnique
title: String!
createdAt: DateTime!
as: A! @relation(name: "C")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment