Skip to content
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
1 change: 1 addition & 0 deletions pgpm/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"dependencies": {
"@pgpmjs/env": "workspace:^",
"@pgpmjs/migrate-client": "workspace:^",
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
Expand Down
46 changes: 39 additions & 7 deletions pgpm/core/src/export/export-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { sync as glob } from 'glob';
import path from 'path';

import { Inquirerer } from 'inquirerer';
import { createClient as createMigrateClient } from '@pgpmjs/migrate-client';

import { PgpmPackage } from '../core/class/pgpm';
import { PgpmRow, SqlWriteOptions, writePgpmFiles, writePgpmPlan } from '../files';
Expand Down Expand Up @@ -309,16 +310,47 @@ export const exportGraphQL = async ({

if (migrateEndpoint) {
console.log(`Fetching sql_actions from ${migrateEndpoint}...`);
const migrateClient = new GraphQLClient({ endpoint: migrateEndpoint, token });
const migrateDb = createMigrateClient({
endpoint: migrateEndpoint,
headers: token ? { Authorization: `Bearer ${token}` } : {},
});

try {
const rawRows = await migrateClient.fetchAllNodes(
'sqlActions',
'id\ndatabaseId\nname\ndeploy\nrevert\nverify\ncontent\ndeps\naction\nactionId\nactorId\npayload',
{ databaseId }
);
const allNodes: Record<string, unknown>[] = [];
let hasNextPage = true;
let afterCursor: string | undefined;

while (hasNextPage) {
const result = await migrateDb.sqlAction.findMany({
select: {
id: true,
databaseId: true,
name: true,
deploy: true,
revert: true,
verify: true,
content: true,
deps: true,
action: true,
actionId: true,
actorId: true,
payload: true,
},
where: { databaseId: { equalTo: databaseId } },
first: 100,
...(afterCursor ? { after: afterCursor } : {}),
}).unwrap();

allNodes.push(
...result.sqlActions.nodes.map(node =>
graphqlRowToPostgresRow(node as Record<string, unknown>)
)
);
hasNextPage = result.sqlActions.pageInfo.hasNextPage;
afterCursor = result.sqlActions.pageInfo.endCursor ?? undefined;
}

sqlActionRows = rawRows.map(graphqlRowToPostgresRow);
sqlActionRows = allNodes;
console.log(` Found ${sqlActionRows.length} sql_actions`);
} catch (err) {
console.warn(` Warning: Could not fetch sql_actions: ${err instanceof Error ? err.message : err}`);
Expand Down
35 changes: 35 additions & 0 deletions pnpm-lock.yaml

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

32 changes: 32 additions & 0 deletions sdk/migrate-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @pgpmjs/migrate-client

Typed GraphQL ORM client for the Constructive Migrate API (`db_migrate` schema).

Generated from `migrate.graphql` via `@constructive-io/graphql-codegen`.

## Usage

```typescript
import { createClient } from '@pgpmjs/migrate-client';

const db = createClient({
endpoint: 'https://migrate.example.com/graphql',
headers: { Authorization: 'Bearer <token>' },
});

// Fetch all sql_actions for a database
const result = await db.sqlAction.findMany({
select: { id: true, name: true, deploy: true, revert: true, verify: true, content: true },
where: { databaseId: { equalTo: '<database-uuid>' } },
}).unwrap();

console.log(result.sqlActions.nodes);
```

## Regeneration

```bash
pnpm generate
```

This runs codegen against `schemas/migrate.graphql` and outputs to `src/`.
54 changes: 54 additions & 0 deletions sdk/migrate-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@pgpmjs/migrate-client",
"version": "0.0.1",
"author": "Constructive <developers@constructive.io>",
"description": "Typed GraphQL ORM client for the Constructive Migrate API (db_migrate schema)",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/constructive-io/constructive",
"license": "MIT",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/constructive-io/constructive"
},
"bugs": {
"url": "https://github.com/constructive-io/constructive/issues"
},
"scripts": {
"clean": "makage clean",
"prepack": "npm run build",
"build": "makage build",
"build:dev": "makage build --dev",
"generate": "tsx scripts/generate.ts",
"lint": "eslint . --fix",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch"
},
"keywords": [
"graphql",
"sdk",
"orm",
"constructive",
"migrate",
"db_migrate",
"pgpm"
],
"dependencies": {
"@0no-co/graphql.web": "^1.1.2",
"@constructive-io/graphql-types": "workspace:^",
"gql-ast": "workspace:^",
"graphql": "^16.13.0"
},
"devDependencies": {
"@constructive-io/graphql-codegen": "workspace:^",
"@types/node": "^22.19.11",
"makage": "^0.1.12",
"tsx": "^4.19.0",
"typescript": "^5.9.3"
}
}
Loading