Skip to content

Commit e522509

Browse files
committed
fix: correct GraphQL field names in integration tests (allDocuments, rowId, searchDocuments, createDocument)
1 parent 02e3ada commit e522509

2 files changed

Lines changed: 38 additions & 37 deletions

File tree

graphile/graphile-pgvector-plugin/src/__tests__/integration.test.ts

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type { PgTestClient } from 'pgsql-test';
55
import { VectorCodecPreset } from '../vector-codec';
66

77
interface DocumentResult {
8-
pgvectorTestDocuments: {
8+
allDocuments: {
99
nodes: Array<{
10-
id: number;
10+
rowId: number;
1111
title: string;
1212
content: string | null;
1313
embedding: number[];
@@ -16,19 +16,19 @@ interface DocumentResult {
1616
}
1717

1818
interface SearchResult {
19-
pgvectorTestSearchDocuments: {
19+
searchDocuments: {
2020
nodes: Array<{
21-
id: number;
21+
rowId: number;
2222
title: string;
2323
embedding: number[];
2424
}>;
2525
};
2626
}
2727

2828
interface CreateDocumentResult {
29-
createPgvectorTestDocument: {
30-
pgvectorTestDocument: {
31-
id: number;
29+
createDocument: {
30+
document: {
31+
rowId: number;
3232
title: string;
3333
embedding: number[];
3434
};
@@ -56,6 +56,7 @@ describe('graphile-pgvector-plugin integration', () => {
5656
schemas: ['pgvector_test'],
5757
preset: testPreset,
5858
useRoot: true,
59+
authRole: 'postgres',
5960
}, [
6061
seed.sqlfile([join(__dirname, './setup.sql')])
6162
]);
@@ -94,9 +95,9 @@ describe('graphile-pgvector-plugin integration', () => {
9495
it('exposes vector column as array of floats', async () => {
9596
const result = await query<DocumentResult>(`
9697
query {
97-
pgvectorTestDocuments(first: 1) {
98+
allDocuments(first: 1) {
9899
nodes {
99-
id
100+
rowId
100101
title
101102
embedding
102103
}
@@ -105,7 +106,7 @@ describe('graphile-pgvector-plugin integration', () => {
105106
`);
106107

107108
expect(result.errors).toBeUndefined();
108-
const nodes = result.data?.pgvectorTestDocuments?.nodes;
109+
const nodes = result.data?.allDocuments?.nodes;
109110
expect(nodes).toBeDefined();
110111
expect(nodes!.length).toBeGreaterThan(0);
111112

@@ -118,7 +119,7 @@ describe('graphile-pgvector-plugin integration', () => {
118119
it('returns correct vector values', async () => {
119120
const result = await query<DocumentResult>(`
120121
query {
121-
pgvectorTestDocuments(condition: { title: "Document A" }) {
122+
allDocuments(condition: { title: "Document A" }) {
122123
nodes {
123124
title
124125
embedding
@@ -128,16 +129,16 @@ describe('graphile-pgvector-plugin integration', () => {
128129
`);
129130

130131
expect(result.errors).toBeUndefined();
131-
const doc = result.data?.pgvectorTestDocuments?.nodes[0];
132+
const doc = result.data?.allDocuments?.nodes[0];
132133
expect(doc?.embedding).toEqual([1, 0, 0]);
133134
});
134135

135136
it('returns all documents with vector data', async () => {
136137
const result = await query<DocumentResult>(`
137138
query {
138-
pgvectorTestDocuments {
139+
allDocuments {
139140
nodes {
140-
id
141+
rowId
141142
title
142143
embedding
143144
}
@@ -146,7 +147,7 @@ describe('graphile-pgvector-plugin integration', () => {
146147
`);
147148

148149
expect(result.errors).toBeUndefined();
149-
const nodes = result.data?.pgvectorTestDocuments?.nodes;
150+
const nodes = result.data?.allDocuments?.nodes;
150151
expect(nodes?.length).toBe(5);
151152
for (const node of nodes!) {
152153
expect(Array.isArray(node.embedding)).toBe(true);
@@ -159,9 +160,9 @@ describe('graphile-pgvector-plugin integration', () => {
159160
it('exposes search function that accepts vector input', async () => {
160161
const result = await query<SearchResult>(`
161162
query {
162-
pgvectorTestSearchDocuments(queryEmbedding: [1, 0, 0]) {
163+
searchDocuments(queryEmbedding: [1, 0, 0]) {
163164
nodes {
164-
id
165+
rowId
165166
title
166167
embedding
167168
}
@@ -170,15 +171,15 @@ describe('graphile-pgvector-plugin integration', () => {
170171
`);
171172

172173
expect(result.errors).toBeUndefined();
173-
const nodes = result.data?.pgvectorTestSearchDocuments?.nodes;
174+
const nodes = result.data?.searchDocuments?.nodes;
174175
expect(nodes).toBeDefined();
175176
expect(nodes!.length).toBeGreaterThan(0);
176177
});
177178

178179
it('returns results ordered by similarity (closest first)', async () => {
179180
const result = await query<SearchResult>(`
180181
query {
181-
pgvectorTestSearchDocuments(queryEmbedding: [1, 0, 0]) {
182+
searchDocuments(queryEmbedding: [1, 0, 0]) {
182183
nodes {
183184
title
184185
embedding
@@ -188,15 +189,15 @@ describe('graphile-pgvector-plugin integration', () => {
188189
`);
189190

190191
expect(result.errors).toBeUndefined();
191-
const nodes = result.data?.pgvectorTestSearchDocuments?.nodes;
192+
const nodes = result.data?.searchDocuments?.nodes;
192193
// Document A [1,0,0] should be closest to query [1,0,0]
193194
expect(nodes![0].title).toBe('Document A');
194195
});
195196

196197
it('respects result_limit parameter', async () => {
197198
const result = await query<SearchResult>(`
198199
query {
199-
pgvectorTestSearchDocuments(queryEmbedding: [1, 0, 0], resultLimit: 2) {
200+
searchDocuments(queryEmbedding: [1, 0, 0], resultLimit: 2) {
200201
nodes {
201202
title
202203
}
@@ -205,7 +206,7 @@ describe('graphile-pgvector-plugin integration', () => {
205206
`);
206207

207208
expect(result.errors).toBeUndefined();
208-
const nodes = result.data?.pgvectorTestSearchDocuments?.nodes;
209+
const nodes = result.data?.searchDocuments?.nodes;
209210
expect(nodes?.length).toBe(2);
210211
});
211212
});
@@ -214,14 +215,14 @@ describe('graphile-pgvector-plugin integration', () => {
214215
it('creates a document with vector embedding', async () => {
215216
const result = await query<CreateDocumentResult>(`
216217
mutation {
217-
createPgvectorTestDocument(input: {
218-
pgvectorTestDocument: {
218+
createDocument(input: {
219+
document: {
219220
title: "New Document"
220221
embedding: [0.5, 0.5, 0.0]
221222
}
222223
}) {
223-
pgvectorTestDocument {
224-
id
224+
document {
225+
rowId
225226
title
226227
embedding
227228
}
@@ -230,7 +231,7 @@ describe('graphile-pgvector-plugin integration', () => {
230231
`);
231232

232233
expect(result.errors).toBeUndefined();
233-
const doc = result.data?.createPgvectorTestDocument?.pgvectorTestDocument;
234+
const doc = result.data?.createDocument?.document;
234235
expect(doc).toBeDefined();
235236
expect(doc!.title).toBe('New Document');
236237
expect(doc!.embedding).toEqual([0.5, 0.5, 0]);
@@ -241,37 +242,37 @@ describe('graphile-pgvector-plugin integration', () => {
241242

242243
const createResult = await query<CreateDocumentResult>(`
243244
mutation($embedding: Vector!) {
244-
createPgvectorTestDocument(input: {
245-
pgvectorTestDocument: {
245+
createDocument(input: {
246+
document: {
246247
title: "Round Trip Test"
247248
embedding: $embedding
248249
}
249250
}) {
250-
pgvectorTestDocument {
251-
id
251+
document {
252+
rowId
252253
embedding
253254
}
254255
}
255256
}
256257
`, { embedding: inputVector });
257258

258259
expect(createResult.errors).toBeUndefined();
259-
const created = createResult.data?.createPgvectorTestDocument?.pgvectorTestDocument;
260+
const created = createResult.data?.createDocument?.document;
260261
expect(created).toBeDefined();
261262

262263
// Read it back
263264
const readResult = await query<DocumentResult>(`
264-
query($id: Int!) {
265-
pgvectorTestDocuments(condition: { id: $id }) {
265+
query($rowId: Int!) {
266+
allDocuments(condition: { rowId: $rowId }) {
266267
nodes {
267268
embedding
268269
}
269270
}
270271
}
271-
`, { id: created!.id });
272+
`, { rowId: created!.rowId });
272273

273274
expect(readResult.errors).toBeUndefined();
274-
const readDoc = readResult.data?.pgvectorTestDocuments?.nodes[0];
275+
const readDoc = readResult.data?.allDocuments?.nodes[0];
275276
// pgvector stores at ~6 decimal precision
276277
for (let i = 0; i < inputVector.length; i++) {
277278
expect(readDoc!.embedding[i]).toBeCloseTo(inputVector[i], 3);

graphile/graphile-pgvector-plugin/src/__tests__/setup.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ INSERT INTO pgvector_test.documents (title, content, embedding) VALUES
2525
('Document E', 'Fifth test document', '[0.577, 0.577, 0.577]');
2626

2727
-- Create a vector search function to test function exposure
28-
CREATE OR REPLACE FUNCTION pgvector_test.search_documents(
28+
CREATE FUNCTION pgvector_test.search_documents(
2929
query_embedding vector(3),
3030
result_limit INT DEFAULT 5
3131
)

0 commit comments

Comments
 (0)