Skip to content

Commit

Permalink
Ensure the fulltext param is passed to aggregated queries (#5346)
Browse files Browse the repository at this point in the history
* Ensure the fulltext param is passed to aggregated queries

* Test for #5345

---------

Co-authored-by: Michael Webb <28074382+mjfwebb@users.noreply.github.com>
  • Loading branch information
nicecatch and mjfwebb authored Jul 12, 2024
1 parent 2264fec commit fd78490
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fresh-toes-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neo4j/graphql-ogm": patch
---

Fixed the `fulltext` argument in OGM aggregate queries
2 changes: 1 addition & 1 deletion packages/ogm/src/classes/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ class Model {
}
`;

const variableValues = { where };
const variableValues = { where, fulltext };

const result = await graphql({
schema: this.schema,
Expand Down
106 changes: 106 additions & 0 deletions packages/ogm/tests/issues/5345.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { Driver, Session } from "neo4j-driver";
import { Neo4jGraphQL } from "@neo4j/graphql";
import { OGM } from "../../src";
import neo4j from "../integration/neo4j";

describe("https://github.com/neo4j/graphql/issues/5345", () => {
let driver: Driver;
let session: Session;
let typeDefs: string;

beforeAll(async () => {
driver = await neo4j();
});

beforeEach(async () => {
session = driver.session();

typeDefs = /* GraphQL */ `
type TestNode @fulltext(indexes: [{ name: "simpleTestIndex", fields: ["name"] }]) {
name: String
}
`;

const neoSchema = new Neo4jGraphQL({
typeDefs,
driver,
});
await neoSchema.getSchema();
await neoSchema.assertIndexesAndConstraints({ driver, options: { create: true } });

try {
await session.run(`
CREATE (:TestNode { name: "jane" })
CREATE (:TestNode { name: "john" })
`);
} finally {
await session.close();
}
});

afterEach(async () => {
const session = driver.session();

try {
await session.run(`
MATCH (n:TestNode)
DETACH DELETE n
`);
} finally {
await session.close();
}
});

afterAll(async () => {
await driver.close();
});

test("Should aggregate using fulltext index", async () => {
const ogm = new OGM({
typeDefs,
driver,
});
await ogm.init();

const model = ogm.model("TestNode");

const fullTextResult = await model.aggregate({
fulltext: {
simpleTestIndex: {
phrase: "jane",
},
},
aggregate: {
count: true,
},
});

const nonFullTextResult = await model.aggregate({
aggregate: {
count: true,
},
});

expect(fullTextResult.count).toBe(1);
expect(nonFullTextResult.count).toBe(2);
});
});

0 comments on commit fd78490

Please # to comment.