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

feat: Return large results as Blob #218

Merged
merged 2 commits into from
Dec 4, 2024
Merged
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
1 change: 1 addition & 0 deletions data-connector/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"privacyMode": 0,
"paranoidMode": 0,
"maxResultLength": 20000,
"connectors": [
{
"type": "postgres",
Expand Down
122 changes: 117 additions & 5 deletions data-connector/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions data-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
"fastify": "^4.28.1",
"graphql": "^16.9.0",
"graphql-tag": "^2.12.6",
"inferable": "^0.30.48",
"inferable": "^0.30.58",
"mysql2": "^3.11.5",
"pg": "^8.13.1",
"sqlite": "^5.1.1",
"sqlite3": "^5.1.7",
"tsx": "^4.19.2"
},
"devDependencies": {
"@faker-js/faker": "^9.1.0",
"@types/node": "^20.11.19",
"@types/pg": "^8.11.10",
"pg": "^8.13.1",
"typescript": "^5.3.3"
}
}
13 changes: 13 additions & 0 deletions data-connector/src/graphql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class GraphQLClient implements DataConnector {
name?: string;
schemaUrl: string;
endpoint: string;
maxResultLength: number;
defaultHeaders?: Record<string, string>;
privacyMode: boolean;
paranoidMode: boolean;
Expand Down Expand Up @@ -176,6 +177,18 @@ To understand the input and output types for this operation, use the searchGraph
};
}

if (JSON.stringify(data).length > this.params.maxResultLength) {
return {
message:
"This query returned too much data. Data was returned to the user directly.",
blob: blob({
name: "Results",
type: "application/json",
data: data,
}),
};
}

return data;
};

Expand Down
9 changes: 9 additions & 0 deletions data-connector/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ const parseConfig = (connector: any) => {
continue;
}

if (!!connector.maxResultLength && isNaN(Number(connector.maxResultLength))) {
throw new Error("maxResultLength must be a number");
}

if (connector.type === "postgres") {
const postgresClient = new PostgresClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
Expand All @@ -63,6 +68,7 @@ const parseConfig = (connector: any) => {
} else if (connector.type === "open-api") {
const openAPIClient = new OpenAPIClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
Expand All @@ -72,6 +78,7 @@ const parseConfig = (connector: any) => {
} else if (connector.type === "graphql") {
const graphQLClient = new GraphQLClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
Expand All @@ -81,6 +88,7 @@ const parseConfig = (connector: any) => {
} else if (connector.type === "mysql") {
const mysqlClient = new MySQLClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
Expand All @@ -90,6 +98,7 @@ const parseConfig = (connector: any) => {
} else if (connector.type === "sqlite") {
const sqliteClient = new SQLiteClient({
...connector,
maxResultLength: Number(config.maxResultLength),
paranoidMode: config.paranoidMode === 1,
privacyMode: config.privacyMode === 1,
});
Expand Down
13 changes: 13 additions & 0 deletions data-connector/src/mysql/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class MySQLClient implements DataConnector {
name?: string;
schema: string;
connectionString: string;
maxResultLength: number;
privacyMode: boolean;
paranoidMode: boolean;
},
Expand Down Expand Up @@ -131,6 +132,18 @@ export class MySQLClient implements DataConnector {
};
}

if (JSON.stringify(rows).length > this.params.maxResultLength) {
return {
message:
"This query returned too much data. Data was returned to the user directly.",
blob: blob({
name: "Results",
type: "application/json",
data: rows,
}),
};
}

return rows;
};

Expand Down
Loading
Loading