Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add graphql query to add document to a component #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions snippets/graphql/add-document-to-component/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
This query can be used to add a document to a component
https://developer.atlassian.com/cloud/compass/graphql/#mutations_addDocument
https://developer.atlassian.com/cloud/compass/graphql/#queries_documentationCategories



Replace cloudId, title, url, ComponentID and documentationCategoryId below in the variables section with the cloudId for your site, title and url of your document, componentID of your Compass component and the documentationcategory ID, and execute the query. You can use the GraphQL explorer to run this query and explore the Compass API further.

NB: The addDocument mutation in Compass is an experimental feature, and you need to explicitly opt in by using the @optIn directive.

First, you need to fetch the DocumentationCategoryID for the components.

STEP 1: => Fetch DocumentationCategoryID for the component

##QUERY


```graphql
query fetchDocumentationCategories($cloudId: ID!, $first: Int, $after: String) {
compass {
documentationCategories(cloudId: $cloudId, first: $first, after: $after) @optIn(to: "compass-beta") {
nodes {
id
name
}
edges {
node {
id
name
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
}

##Query Variables

```graphql
{
"cloudId": "YOUR-CLOUD-ID",
"first": 10,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you could limit this to just 4 as right now the categories are static so you won't ever get back more than that for a given site.

"after": null
}


From the above result, you will get the Document Category ID in the ARI format for the following types:

Discover
Contributor
Maintainer
Other

Step 2: Use the following query to add a document to your Compass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should be "Use the following mutation ... "


##QUERY

```graphql
mutation addDocument($input: CompassAddDocumentInput!) {
compass {
addDocument(input: $input) @optIn(to: "compass-beta") {
success
errors {
message
}
documentDetails {
id
title
url
componentId
documentationCategoryId
}
}
}
}

##QUERY VARIABLES

```graphql
{
"input": {
"title": "title",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth calling out (in a comment or further above in the readme) that title is optional and you can just supply a url?

"url": "your-doc-url",
"componentId": "Your-component-id",
"documentationCategoryId": "your-documentationcateoryid"
}
}

17 changes: 17 additions & 0 deletions snippets/graphql/add-document-to-component/addDocument.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
mutation addDocument($input: CompassAddDocumentInput!) {
compass {
addDocument(input: $input) @optIn(to: "compass-beta") {
success
errors {
message
}
documentDetails {
id
title
url
componentId
documentationCategoryId
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
query fetchDocumentationCategories($cloudId: ID!, $first: Int, $after: String) {
compass {
documentationCategories(cloudId: $cloudId, first: $first, after: $after) @optIn(to: "compass-beta") {
nodes {
id
name
}
edges {
node {
id
name
}
cursor
}
pageInfo {
hasNextPage
endCursor
}
}
}
}