Create Post Type
Creating and modifying post types is in beta and under active development at this moment. Please do not use the queries and mutations in production environments.
This tutorial is a walk through of creating a sample post type like Question.
Each post has a type which defines the fields of it and we can create our own post type.
You can use postTypes query to retrieve the
available post types in your community.
query {
postTypes(limit: 10) {
nodes {
id
name
postFields {
fields {
key
name
type
}
}
}
}
}
postFields.fields defines the fields of the post.
It is an array of CustomFieldsSchema.
The important attributes are key and type:
keyis the identifier of this field and can not be changed.typecan be one ofCustomFieldTypeenum values.
An example of a post type can look like below:
{
"id": "YP4thX1J1SM",
"name": "Discussion",
"postFields": {
"fields": [
{
"key": "title",
"name": "Title",
"type": "text"
},
{
"key": "content",
"name": "Content",
"type": "richText"
}
]
}
}
This is the post type for discussion. It has 2 fields: title and content.
title should have a text value and content can contain rich text (HTML).
Create a Post Type
Creating and modifying post types is only available on the Enterprise plan.
createPostType mutation is used to create a new post types
and it takes CreatePostTypeInput as input.
Here is an example of creating Question post type:
mutation {
createPostType(
input: {
context: post
name: "Question"
pluralName: "Questions"
primaryReactionType: VOTE_BASE
slug: "community-question"
validReplyTypesIds: []
postFields: {
fields: [
{
name: "Title"
key: "title"
type: text
}
{
name: "Resolved"
key: "resolved"
settings: [
{ key: "subtype", value: "toggle" }
{ key: "view", value: "Pill" }
{
key: "viewProps"
value: "{\"trueText\":\"Resolved\",\"falseText\":\"\"}"
}
]
type: boolean
}
{
name: "Content"
key: "content"
type: richText
}
]
}
}
) {
id
name
}
}
Required inputs:
contextcan bepostorreply. As an example, Question has the context ofpost, and Answer hasreplycontext. Check outPostTypeContextfor more information.nameandpluralNameare the name of the post type in singular and plural (e.g. Question and Questions).primaryReactionTypedefines the way members can react to a post. For more information check outReactionType.slugis the unique identifier of your post type and cannot be changed.postFieldsdefine the schema and appearance of the post and it is an array ofCustomFieldsSchemaInput. In this case, we have 3 fields.nameis going be appear on the post creation form.keyis the identifier of this field and it must be unique.typedefines the field type. Check outCustomFieldTypeto find out all available types.settingsis a freeform key/value storage defining the appearance of the field. The value should be a valid stringified JSON object. In the above example,subtypedefines that the form component should be a toggle.view/viewPropsdefine that the field should be shown as a Pill and when the value istruethe Pill text should be "Resolved".
Add a New Field to Post Type
Adding, updating, and archiving post fields is only available on the Premium and above plan.
addPostTypeField mutation is used to add a new field to a post type,
and it takes id of target post type and CustomFieldsSchemaInput as inputs.
mutation {
addPostTypeField(
id: "pv12w6z1LEO6"
input: {
key: "date"
name: "Date"
type: date
}
) {
id
}
}
This mutation adds a date field to the target post type.
Archive and Unarchive a Post Field
Archive a Post Field
archivePostTypeField mutation is used to archive a field in a post type.
It takes id and key of target post type as inputs.
mutation {
(id: "pv12w6z1LEO6", key: "date") {
id
}
Archiving a field does not remove the value of the field from the posts and you can unarchive and the values will be reverted.
Unarchive a Post Field
unarchivePostTypeField mutation is used to unarchive a field in a post type.
It takes id and key of target post type as inputs.
mutation {
unarchivePostTypeField(id: "pv12w6z1LEO6", key: "date") {
id
}