Skip to content

Allow to configure the api url path #22

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

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
28 changes: 27 additions & 1 deletion src/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ export class QueryEditor extends PureComponent<Props> {
onChange({ ...query, queryText: event.target.value });
};

onFieldApiUrlPathChange = (event: ChangeEvent<HTMLInputElement>) => {
const { onChange, query } = this.props;
onChange({ ...query, fieldApiUrlPath: event.target.value });
};

onDataApiUrlPathChange = (event: ChangeEvent<HTMLInputElement>) => {
const { onChange, query } = this.props;
onChange({ ...query, dataApiUrlPath: event.target.value });
};

render() {
const query = defaults(this.props.query, defaultQuery);
const { queryText } = query;
const { queryText, fieldApiUrlPath, dataApiUrlPath } = query;
return (
<div className="gf-form">
<FormField
Expand All @@ -29,6 +39,22 @@ export class QueryEditor extends PureComponent<Props> {
label="Query String"
tooltip="The query string for data endpoint of the node graph api; i.e. /api/graph/data?query=sometext"
/>
<FormField
labelWidth={8}
inputWidth={20}
value={fieldApiUrlPath || '/api/graph/field'}
onChange={this.onFieldApiUrlPathChange}
label="Field Endpoint"
tooltip="The field endpoint of the node graph api"
/>
<FormField
labelWidth={8}
inputWidth={20}
value={dataApiUrlPath || '/api/graph/data'}
onChange={this.onDataApiUrlPathChange}
label="Data Endpoint"
tooltip="The data endpoint of the node graph api"
/>
</div>
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
const query = defaults(target, defaultQuery);
const dataQuery = getTemplateSrv().replace(query.queryText, options.scopedVars);
// fetch graph fields from api
const responseGraphFields = await this.doRequest('/api/graph/fields', `${dataQuery}`);
const fieldApiUrlPath = getTemplateSrv().replace(query.fieldApiUrlPath, options.scopedVars);
const responseGraphFields = await this.doRequest(`${fieldApiUrlPath}`, `${dataQuery}`);
// fetch graph data from api
const responseGraphData = await this.doRequest('/api/graph/data', `${dataQuery}`);
const dataApiUrlPath = getTemplateSrv().replace(query.dataApiUrlPath, options.scopedVars);
const responseGraphData = await this.doRequest(`${dataApiUrlPath}`, `${dataQuery}`);
// extract fields of the nodes and edges in the graph fields object
const nodeFieldsResponse = responseGraphFields.data.nodes_fields;
const edgeFieldsResponse = responseGraphFields.data.edges_fields;
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import { DataQuery, DataSourceJsonData } from '@grafana/data';

export interface MyQuery extends DataQuery {
queryText?: string;
fieldApiUrlPath: string;
dataApiUrlPath: string;
}

export const defaultQuery: Partial<MyQuery> = {};
export const defaultQuery: Partial<MyQuery> = {
fieldApiUrlPath: '/api/graph/fields',
dataApiUrlPath: '/api/graph/data',
};

/**
* These are options configured for each DataSource instance
Expand Down