Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions .changeset/@graphql-mesh_postgraphile-9342-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@graphql-mesh/postgraphile": patch
---
dependencies updates:
- Updated dependency [`postgraphile@^5.0.0` ↗︎](https://www.npmjs.com/package/postgraphile/v/5.0.0) (from `^4.13.0`, in `dependencies`)
- Added dependency [`@dataplan/pg@^1.0.0` ↗︎](https://www.npmjs.com/package/@dataplan/pg/v/1.0.0) (to `dependencies`)
- Added dependency [`grafast@^1.0.0` ↗︎](https://www.npmjs.com/package/grafast/v/1.0.0) (to `dependencies`)
- Removed dependency [`postgraphile-core@^4.13.0` ↗︎](https://www.npmjs.com/package/postgraphile-core/v/4.13.0) (from `dependencies`)
7 changes: 7 additions & 0 deletions .changeset/postgraphile-v1-transport-and-loader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@graphql-mesh/transport-postgraphile": minor
"@omnigraph/postgraphile": minor
"@graphql-mesh/postgraphile": patch
---

Introduce new PostGraphile v5 source handler and transport for Mesh v1, using PostGraphile stable v5.0.0
33 changes: 33 additions & 0 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,36 @@ declare module '@newrelic/test-utilities' {

declare var __VERSION__: string | undefined;
declare var __PACKED_DEPS_PATH__: string | undefined;

// Ambient declarations for PostGraphile v5 subpath exports.
// These act as fallbacks for `moduleResolution: node` (used in tsconfig.build.json)
// which cannot resolve package `exports` subpath entries.
// With `moduleResolution: bundler` (tsconfig.json) the actual package types take
// precedence and these declarations are ignored.
declare module 'postgraphile/presets/amber' {
export const PostGraphileAmberPreset: GraphileConfig.Preset;
export default PostGraphileAmberPreset;
}

declare module '@dataplan/pg/adaptors/pg' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function makePgService(
opts: any,
): GraphileConfig.PgServiceConfiguration<'@dataplan/pg/adaptors/pg'>;
}

// Ensure GraphileConfig.PgAdaptors is aware of the `@dataplan/pg/adaptors/pg`
// adaptor key even when the subpath cannot be resolved via `moduleResolution: node`.
// Without this augmentation, `keyof GraphileConfig.PgAdaptors` evaluates to `never`,
// which makes `GraphileConfig.Preset.pgServices` element type `never[]`, causing
// TypeScript 6's stricter `any`-to-`never` assignment check to fail (TS2322).
declare namespace GraphileConfig {
interface PgAdaptors {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'@dataplan/pg/adaptors/pg': {
adaptorSettings: any;
makePgServiceOptions: any;
client: any;
};
}
}
15 changes: 15 additions & 0 deletions e2e/postgraphile/mesh.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Opts } from '@e2e/opts';
import { defineConfig } from '@graphql-mesh/compose-cli';
import { loadPostgraphileSubgraph } from '@omnigraph/postgraphile';

const opts = Opts(process.argv);

export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadPostgraphileSubgraph('Library', {
connectionString: `postgresql://postgres:password@localhost:${opts.getServicePort('postgres')}/library`,
}),
},
],
});
8 changes: 8 additions & 0 deletions e2e/postgraphile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@e2e/postgraphile",
"private": true,
"dependencies": {
"@graphql-hive/gateway": "^2.5.11",
"graphql": "^16.13.1"
}
}
57 changes: 57 additions & 0 deletions e2e/postgraphile/postgraphile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { createTenv, type Container } from '@e2e/tenv';

const { compose, container, serve } = createTenv(__dirname);

let postgres: Container;

beforeAll(async () => {
postgres = await container({
name: 'postgres',
image: 'postgres:16-alpine',
containerPort: 5432,
env: {
POSTGRES_USER: 'postgres',
POSTGRES_PASSWORD: 'password',
POSTGRES_DB: 'library',
},
volumes: [
{
host: 'seed.sql',
container: '/docker-entrypoint-initdb.d/seed.sql',
},
],
healthcheck: ['CMD-SHELL', 'pg_isready -U postgres'],
});
});

it('should compose the appropriate schema', async () => {
const composition = await compose({
services: [postgres],
maskServicePorts: true,
});
expect(composition.result).toMatchSnapshot();
});

it('should execute BooksWithAuthors', async () => {
const composition = await compose({
services: [postgres],
output: 'graphql',
});
const gw = await serve({ supergraph: composition.output });
const result = await gw.execute({
query: /* GraphQL */ `
query BooksWithAuthors {
allBooks(orderBy: [ID_ASC], first: 2) {
nodes {
title
year
authorByAuthorId {
name
}
}
}
}
`,
});
expect(result).toMatchSnapshot();
});
23 changes: 23 additions & 0 deletions e2e/postgraphile/seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Sample seed data for the PostGraphile e2e test
CREATE TABLE IF NOT EXISTS author (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
bio TEXT
);

CREATE TABLE IF NOT EXISTS book (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
author_id INTEGER REFERENCES author(id),
year INTEGER
);

INSERT INTO author (name, bio) VALUES
('J.R.R. Tolkien', 'English author of high fantasy'),
('George Orwell', 'English novelist and essayist');

INSERT INTO book (title, author_id, year) VALUES
('The Lord of the Rings', 1, 1954),
('The Hobbit', 1, 1937),
('1984', 2, 1949),
('Animal Farm', 2, 1945);
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if (process.env.E2E_TEST && process.env.CI && !isLinux) {
testMatch.push('!**/e2e/neo4j-example/**');
testMatch.push('!**/e2e/soap-demo/**');
testMatch.push('!**/e2e/mysql-employees/**');
testMatch.push('!**/e2e/postgraphile/**');
testMatch.push('!**/e2e/opentelemetry/**');
if (isWindows) {
testMatch.push('!**/e2e/tsconfig-paths/**');
Expand Down
4 changes: 2 additions & 2 deletions packages/fusion/composition/src/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function getAnnotatedSubgraphs(
astNode: undefined,
});
},
[MapperKind.FIELD]: (fieldConfig, fieldName) => {
[MapperKind.FIELD]: ((fieldConfig, fieldName) => {
if (!sourceDirectiveUsed) {
return fieldConfig;
}
Expand Down Expand Up @@ -199,7 +199,7 @@ export function getAnnotatedSubgraphs(
},
astNode: undefined,
};
},
}) as any,
[MapperKind.ENUM_VALUE]: (valueConfig, _typeName, _schema, externalValue) => {
if (!sourceDirectiveUsed) {
return valueConfig;
Expand Down
4 changes: 2 additions & 2 deletions packages/fusion/composition/src/transforms/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export function createFederationTransform(config: FederationTransformConfig): Su
};
}
},
[MapperKind.FIELD]: (fieldConfig, fieldName, typeName) => {
[MapperKind.FIELD]: ((fieldConfig, fieldName, typeName) => {
const fieldTransformConfig = configurationByField.get(typeName)?.get(fieldName);
if (fieldTransformConfig) {
const fieldDirectives = getDirectiveExtensions(fieldConfig) || {};
Expand Down Expand Up @@ -420,7 +420,7 @@ export function createFederationTransform(config: FederationTransformConfig): Su
},
};
}
},
}) as any,
});
subgraphSchema = addFederation2DirectivesToSubgraph(subgraphSchema);
subgraphSchema = importFederationDirectives(subgraphSchema, [...usedFederationDirectives]);
Expand Down
3 changes: 1 addition & 2 deletions packages/legacy/handlers/graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type {
DocumentNode,
ExecutionResult,
GraphQLResolveInfo,
IntrospectionQuery,
SelectionNode,
Expand Down Expand Up @@ -46,7 +45,7 @@ import {
} from '@graphql-mesh/utils';
import type { SubscriptionProtocol } from '@graphql-tools/url-loader';
import { UrlLoader } from '@graphql-tools/url-loader';
import type { ExecutionRequest, Executor } from '@graphql-tools/utils';
import type { ExecutionRequest, ExecutionResult, Executor } from '@graphql-tools/utils';
import {
getDocumentNodeFromSchema,
getOperationASTFromRequest,
Expand Down
5 changes: 3 additions & 2 deletions packages/legacy/handlers/postgraphile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
"graphql": "*"
},
"dependencies": {
"@dataplan/pg": "^1.0.0",
"@graphql-mesh/cross-helpers": "^0.4.12",
"@graphql-mesh/store": "^0.104.34",
"@graphql-mesh/string-interpolation": "^0.5.16",
"@graphql-mesh/types": "^0.104.25",
"@graphql-mesh/utils": "^0.104.32",
"@graphql-tools/delegate": "^12.0.12",
"grafast": "^1.0.0",
"pg": "^8.20.0",
"postgraphile": "^4.13.0",
"postgraphile-core": "^4.13.0",
"postgraphile": "^5.0.0",
"tslib": "^2.4.0"
},
"devDependencies": {
Expand Down
Loading
Loading