Skip to content

Instantly share code, notes, and snippets.

@thomsbg
Last active May 12, 2020 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomsbg/c99d6212eff225c0ceb1470d65dfd85c to your computer and use it in GitHub Desktop.
Save thomsbg/c99d6212eff225c0ceb1470d65dfd85c to your computer and use it in GitHub Desktop.
List + Association (Inline) Input patterns
input <%= association %>InlineInput {
connect: <%= association %>UniqueIdInput
create: <%= association %>CreateInput
createOrUpdate: <%= association %>CreateOrUpdateInlineInput
# Update-only. Should these be in a separate type?
update: <%= association %>UpdateInlineInput
disconnect: Boolean
}
input <%= association %>InlineListInput {
connect: [<%= association %>ConnectInlineInput!]
create: [<%= association %>CreateInput!]
createOrUpdate: [<%= association %>CreateOrUpdateInlineInput!]
# Update-only. Should these be in a separate type?
update: [<%= association %>UpdateInlineInput!]
disconnect: [<%= association %>UniqueIdInput!]
replace: [<%= association %>UniqueIdInput!] # Overwrite the full list rather than add to it.
}
# Specify an existing record to link to.
input <%= association %>ConnectInlineInput {
where: <%= association %>UniqueIdInput
# Defaults to appending to the end of the list.
position: <%= association %>ConnectPositionInput
}
# Specify the position of the newly connected item in a list of siblings.
input <%= association %>ConnectPositionInput {
before: <%= association %>UniqueIdInput
after: <%= association %>UniqueIdInput
# If positive, insert _before_ the element at `index` (0-based).
# If negative, insert _after_ the element at `length + index`.
index: Int
}
# Similar to the arguments of a root-level update<%= association %> mutation, but wrapped into an object.
input <%= association %>UpdateInlineInput {
where: <%= association %>UniqueIdInput
input: <%= association %>UpdateInput
}
# Similar to the arguments of a root-level createOrUpdate<%= association %> mutation, but wrapped into an object.
input <%= association %>CreateOrUpdateInlineInput {
# Identify a record to optionally update. A new record will be created if no matching record is found.
where: <%= association %>UniqueIdInput
# Input used to create.
create: <%= association %>CreateInput!
# Input used to update, optional if no changes are needed.
update: <%= association %>UpdateInput
}
# Which fields are available here will vary per type.
# Each of these must be a unique key that is immediately consistent after a create/update/createOrUpdate mutation.
input <%= association %>UniqueIdInput {
id: ID
uuid: ID
externalID: ID
slug: String
name: String
url: URL
}
# Specify changes to apply to a list of <%= typeName %> objects.
# If the list is being created from scratch, these changes are implicitly applied to the empty list.
input <%= typeName %>ListInput {
# Create one or more new <%= typeName %> objects to add to the list.
# Existing list items are not removed.
add: [<%= typeName %>ListAddInput!]
# Move one or more list items to new positions within the list.
move: [<%= typeName %>ListMoveInput!]
# Remove one or more list items.
remove: [<%= typeName %>ListItemIdInput!]
# Replace the entire list with newly created items.
replace: [<%= typeName %>Input!]
# Update one or more existing <%= typeName %> items.
update: [<%= typeName %>ListUpdateInput!]
}
# Create a new <%= typeName %> and insert it into the list at the given position.
input <%= typeName %>ListAddInput {
input: <%= typeName %>Input!
position: <%= typeName %>ListPositionInput
}
# Update an existing <%= typeName %>.
input <%= typeName %>ListUpdateInput {
where: <%= typeName %>ListItemIdInput!
input: <%= typeName %>Input!
}
# Move an existing <%= typeName %> to a new position within the list.
input <%= typeName %>ListMoveInput {
where: <%= typeName %>ListItemIdInput!
position: <%= typeName %>ListPositionInput!
}
# Specify which position that a particular <%= typeName %> should appear at in a list.
input <%= typeName %>ListPositionInput {
index: Int
before: <%= typeName %>ListItemIdInput
after: <%= typeName %>ListItemIdInput
}
# Identify an existing <%= typeName %> within a list.
input <%= typeName %>ListItemIdInput {
index: Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment