Sorry for posting this in the Forge category - but there isn’t a Compass category on here…
So I’m trying to build a Compass app, but it seems that it’s mostly all about the component that you’re in right now. Does anyone know how I can get hold of all of the data providers, event sources etc associated with a component?
Is it possible?
Thanks,
/Daniel
2 Likes
Hey @danielwester
Thanks for this question! I’m the PM for the Compass developer platform so I’ll do my best to answer this one 
To fetch information about Compass components from a Forge app, the best approach is to include the Forge GraphQL Toolkit in your app. You should find everything you’re looking for in the CompassRequests
class.
For example, to get the event sources for a component, use the getComponent method with "includeEventSources": true
.
If you need any help navigating the schema please let me know!
PS - For those interested, the developer platform for Compass is built on Forge, and it’s ready for active development today. Look for a more official announcement soon, but in the meantime please head here to get started:
http://go.atlassian.com/compass-developer
2 Likes
Thank you for this. It got me a step closer…
So from the above I get:
"eventSources": [
{
"id": "ari:cloud:compass: xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx:event-source/224f3cc1-xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx/xxxxxxx",
"externalEventSourceId": "pagerduty_ xxxxxxx",
"eventType": "INCIDENT",
"forgeAppId": "xxxxxx-b656-4127-a685-xxxxxxx"
}
],
(ids hidden)
which I then use with:
console.log( await graphqlGateway.compass.asUser().getEventSource({
cloudId: req.context.cloudId,
eventType: eventSource.eventType,
externalEventSourceId: eventSource.externalEventSourceId
}))
(where eventSource is the previousObject).
The output from that is:
{
errors: [
{
errorSource: 'UNDERLYING_SERVICE',
errorType: 'DataFetchingException',
message: "This event source doesn't exist. Check for typos and try again."
}
],
success: false,
data: { eventSource: null }
}
I’m hoping I’m missing something silly…
Hey @danielwester ! You’ve found a (unintended) limitation in our GraphQL toolkit- currently there’s no way for a Forge app to retrieve an event source that was created by another app. We’re working on exposing a new method that will allow you to do this. Will post an update here when it’s available.
2 Likes
@danielwester An update! While we work on making this action possible through the GraphQL toolkit, it is currently possible by calling the GraphQL API directly. So here’s some sample code you can use today:
To get all events for a component:
import api from '@forge/api'
const eventsQuery = `query example_events_through_component(
$id: ID!
$eventQuery: CompassEventsQuery
) {
compass {
component(id: $id) {
... on CompassComponent {
id
events(query: $eventQuery) {
... on CompassEventConnection {
nodes {
eventType
url
displayName
description
lastUpdated
}
}
}
}
... on QueryError {
message
extensions {
statusCode
errorType
}
}
}
}
}`;
const variables = {
id: 'COMPONENT_ID',
eventQuery: { first: 100 },
};
const headers = { 'X-ExperimentalApi': 'compass-beta, compass-prototype' };
const request = await api.asApp().requestGraph(eventsQuery, variables, headers);
const result = await request.json();
const component = result.data.compass.component as CompassComponent;
console.log(component.events);
To get event sources with events for a component:
import api from '@forge/api'
const eventSourcesQuery = `query example_events_through_component_sources(
$id: ID!
$eventQuery: CompassEventsInEventSourceQuery
) {
compass {
component(id: $id) {
... on CompassComponent {
id
eventSources {
events(query: $eventQuery) {
... on CompassEventConnection {
nodes {
eventType
url
displayName
description
lastUpdated
}
}
}
}
}
... on QueryError {
message
extensions {
statusCode
errorType
}
}
}
}
}`;
const variables = {
id: 'COMPONENT_ID',
eventQuery: { first: 100 },
};
const headers = { 'X-ExperimentalApi': 'compass-beta, compass-prototype' };
const request = await api.asApp().requestGraph(eventSourcesQuery, variables, headers);
const result = await request.json();
const component = result.data.compass.component as CompassComponent;
console.log(component.eventSources[0].events);
Hope this helps you get unblocked!
2 Likes