Skip to main content

Create Post Type

note

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:

  • key is the identifier of this field and can not be changed.
  • type can be one of CustomFieldType enum 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

note

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:

  • context can be post or reply. As an example, Question has the context of post, and Answer has reply context. Check out PostTypeContext for more information.
  • name and pluralName are the name of the post type in singular and plural (e.g. Question and Questions).
  • primaryReactionType defines the way members can react to a post. For more information check out ReactionType.
  • slug is the unique identifier of your post type and cannot be changed.
  • postFields define the schema and appearance of the post and it is an array of CustomFieldsSchemaInput. In this case, we have 3 fields.
    • name is going be appear on the post creation form.
    • key is the identifier of this field and it must be unique.
    • type defines the field type. Check out CustomFieldType to find out all available types.
    • settings is a freeform key/value storage defining the appearance of the field. The value should be a valid stringified JSON object. In the above example, subtype defines that the form component should be a toggle. view/viewProps define that the field should be shown as a Pill and when the value is true the Pill text should be "Resolved".

Add a New Field to Post Type

note

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
}
note

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
}