-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate connector builder api client (#18274)
* update openapi for connector builder to work with orval for now * add orval configuration for generating the connector builder client * create ConnectorBuilderApiService with methods to call the generated connector builder API client code * rename connector definition to manifest * refactor builder api service to match existing patterns * fix name of pages folder * improve comment * modify structure of StreamRead * fix path
- Loading branch information
Showing
9 changed files
with
200 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
airbyte-webapp/src/core/domain/connectorBuilder/ConnectorBuilderRequestService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { | ||
StreamRead, | ||
StreamReadRequestBody, | ||
StreamsListRead, | ||
StreamsListRequestBody, | ||
} from "core/request/ConnectorBuilderClient"; | ||
|
||
import { AirbyteRequestService } from "../../request/AirbyteRequestService"; | ||
|
||
export class ConnectorBuilderRequestService extends AirbyteRequestService { | ||
public readStream(readParams: StreamReadRequestBody): Promise<StreamRead> { | ||
// TODO: uncomment this and remove mock responses once there is a real API to call | ||
// return readStream(readParams, this.requestOptions); | ||
console.log("------------"); | ||
console.log(`Stream: ${readParams.stream}`); | ||
console.log(`Connector manifest:\n${JSON.stringify(readParams.manifest)}`); | ||
console.log(`Config:\n${JSON.stringify(readParams.config)}`); | ||
return new Promise((resolve) => setTimeout(resolve, 200)).then(() => { | ||
return { | ||
logs: [ | ||
{ level: "INFO", message: "Syncing stream: rates " }, | ||
{ level: "INFO", message: "Setting state of rates stream to {'date': '2022-09-25'}" }, | ||
], | ||
slices: [ | ||
{ | ||
sliceDescriptor: { start: "Jan 1, 2022", end: "Jan 2, 2022" }, | ||
state: { | ||
type: "STREAM", | ||
stream: { stream_descriptor: { name: readParams.stream }, stream_state: { date: "2022-09-26" } }, | ||
data: { rates: { date: "2022-09-26" } }, | ||
}, | ||
pages: [ | ||
{ | ||
records: [ | ||
{ | ||
stream: readParams.stream, | ||
data: { | ||
id: "dp_123", | ||
object: readParams.stream, | ||
amount: 2000, | ||
balance_transaction: "txn_123", | ||
}, | ||
}, | ||
], | ||
request: { | ||
url: "https://api.com/path", | ||
}, | ||
response: { | ||
status: 200, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
}); | ||
} | ||
|
||
public listStreams(listParams: StreamsListRequestBody): Promise<StreamsListRead> { | ||
// TODO: uncomment this and remove mock responses once there is a real API to call | ||
// return listStreams(listParams, this.requestOptions); | ||
console.log(`Received listStreams body: ${JSON.stringify(listParams)}`); | ||
return new Promise((resolve) => setTimeout(resolve, 200)).then(() => { | ||
return { | ||
streams: [ | ||
{ | ||
name: "disputes", | ||
url: "https://api.com/disputes", | ||
}, | ||
{ | ||
name: "transactions", | ||
url: "https://api.com/transactions", | ||
}, | ||
{ | ||
name: "users", | ||
url: "https://api.com/users", | ||
}, | ||
], | ||
}; | ||
}); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
airbyte-webapp/src/services/connectorBuilder/ConnectorBuilderApiService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useQuery } from "react-query"; | ||
|
||
import { useConfig } from "config"; | ||
import { ConnectorBuilderRequestService } from "core/domain/connectorBuilder/ConnectorBuilderRequestService"; | ||
import { | ||
StreamReadRequestBody, | ||
StreamReadRequestBodyConfig, | ||
StreamReadRequestBodyManifest, | ||
StreamsListRequestBody, | ||
} from "core/request/ConnectorBuilderClient"; | ||
import { useSuspenseQuery } from "services/connector/useSuspenseQuery"; | ||
import { useDefaultRequestMiddlewares } from "services/useDefaultRequestMiddlewares"; | ||
import { useInitService } from "services/useInitService"; | ||
|
||
const connectorBuilderKeys = { | ||
all: ["connectorBuilder"] as const, | ||
read: (streamName: string, manifest: StreamReadRequestBodyManifest, config: StreamReadRequestBodyConfig) => | ||
[...connectorBuilderKeys.all, "read", { streamName, manifest, config }] as const, | ||
list: (manifest: StreamReadRequestBodyManifest) => [...connectorBuilderKeys.all, "list", { manifest }] as const, | ||
}; | ||
|
||
function useConnectorBuilderService() { | ||
const config = useConfig(); | ||
const middlewares = useDefaultRequestMiddlewares(); | ||
return useInitService( | ||
() => new ConnectorBuilderRequestService(config.connectorBuilderApiUrl, middlewares), | ||
[config.connectorBuilderApiUrl, middlewares] | ||
); | ||
} | ||
|
||
export const useReadStream = (params: StreamReadRequestBody) => { | ||
const service = useConnectorBuilderService(); | ||
|
||
return useQuery( | ||
connectorBuilderKeys.read(params.stream, params.manifest, params.config), | ||
() => service.readStream(params), | ||
{ refetchOnWindowFocus: false, enabled: false } | ||
); | ||
}; | ||
|
||
export const useListStreams = (params: StreamsListRequestBody) => { | ||
const service = useConnectorBuilderService(); | ||
|
||
return useSuspenseQuery(connectorBuilderKeys.list(params.manifest), () => service.listStreams(params)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters