Skip to content

Commit

Permalink
Remove non-suffixed relationship filters (#5637)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrellwarde authored Oct 9, 2024
1 parent 4438b60 commit 8832dd6
Show file tree
Hide file tree
Showing 118 changed files with 307 additions and 1,192 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-mice-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@neo4j/graphql": major
"@neo4j/graphql-ogm": major
---

Remove deprecated relationship filters without suffix. Queries which previously used these should migrate over to `_SOME` filters.
29 changes: 3 additions & 26 deletions packages/graphql/src/schema/generation/augment-where-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@
*/

import type { Directive, InputTypeComposerFieldConfigMapDefinition } from "graphql-compose";
import { DEPRECATED } from "../../constants";
import type { RelationshipAdapter } from "../../schema-model/relationship/model-adapters/RelationshipAdapter";
import type { RelationshipDeclarationAdapter } from "../../schema-model/relationship/model-adapters/RelationshipDeclarationAdapter";
import type { Neo4jFeaturesSettings } from "../../types";
import { shouldAddDeprecatedFields } from "./utils";

function augmentWhereInputType({
whereType,
fieldName,
filters,
relationshipAdapter,
deprecatedDirectives,
features,
}: {
whereType: string;
fieldName: string;
Expand All @@ -42,14 +38,13 @@ function augmentWhereInputType({
| undefined;
relationshipAdapter: RelationshipAdapter | RelationshipDeclarationAdapter;
deprecatedDirectives: Directive[];
features: Neo4jFeaturesSettings | undefined;
}): InputTypeComposerFieldConfigMapDefinition {
const fields: InputTypeComposerFieldConfigMapDefinition = {};
if (!relationshipAdapter.isFilterableByValue()) {
return fields;
}

if (!relationshipAdapter.isList || shouldAddDeprecatedFields(features, "arrayFilters")) {
if (!relationshipAdapter.isList) {
fields[fieldName] = {
type: whereType,
};
Expand All @@ -63,20 +58,6 @@ function augmentWhereInputType({
// e.g. "Return Movies where all of the related Actors match this filter"
description: filterField.description,
};

if (shouldAddDeprecatedFields(features, "arrayFilters")) {
// TODO: are these deprecations still relevant?
// only adding these for the deprecation message. If no deprecation anymore, delete them.
fields[fieldName] = {
type: whereType,
directives: [
{
name: DEPRECATED,
args: { reason: `Use \`${fieldName}_SOME\` instead.` },
},
],
};
}
}
}

Expand All @@ -85,8 +66,7 @@ function augmentWhereInputType({

export function augmentWhereInputTypeWithRelationshipFields(
relationshipAdapter: RelationshipAdapter | RelationshipDeclarationAdapter,
deprecatedDirectives: Directive[],
features: Neo4jFeaturesSettings | undefined
deprecatedDirectives: Directive[]
): InputTypeComposerFieldConfigMapDefinition {
const filters = relationshipAdapter.listFiltersModel?.filters;
return augmentWhereInputType({
Expand All @@ -95,14 +75,12 @@ export function augmentWhereInputTypeWithRelationshipFields(
filters,
relationshipAdapter,
deprecatedDirectives,
features,
});
}

export function augmentWhereInputTypeWithConnectionFields(
relationshipAdapter: RelationshipAdapter | RelationshipDeclarationAdapter,
deprecatedDirectives: Directive[],
features: Neo4jFeaturesSettings | undefined
deprecatedDirectives: Directive[]
): InputTypeComposerFieldConfigMapDefinition {
const filters = relationshipAdapter.listFiltersModel?.connectionFilters;
return augmentWhereInputType({
Expand All @@ -111,6 +89,5 @@ export function augmentWhereInputTypeWithConnectionFields(
filters,
relationshipAdapter,
deprecatedDirectives,
features,
});
}
8 changes: 2 additions & 6 deletions packages/graphql/src/schema/generation/where-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,10 @@ export function withSourceWhereInputType({
const relationshipTarget = relationshipAdapter.target;
const relationshipSource = relationshipAdapter.source;
const whereInput = composer.getITC(relationshipSource.operations.whereInputTypeName);
const fields = augmentWhereInputTypeWithRelationshipFields(relationshipAdapter, deprecatedDirectives, features);
const fields = augmentWhereInputTypeWithRelationshipFields(relationshipAdapter, deprecatedDirectives);
whereInput.addFields(fields);

const connectionFields = augmentWhereInputTypeWithConnectionFields(
relationshipAdapter,
deprecatedDirectives,
features
);
const connectionFields = augmentWhereInputTypeWithConnectionFields(relationshipAdapter, deprecatedDirectives);
whereInput.addFields(connectionFields);

// TODO: Current unions are not supported as relationship targets beyond the above fields
Expand Down
1 change: 0 additions & 1 deletion packages/graphql/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ export type Neo4jFeaturesSettings = {
**/
excludeDeprecatedFields?: {
implicitEqualFilters?: boolean;
arrayFilters?: boolean;
aggregationFilters?: boolean;
deprecatedOptionsArgument?: boolean;
nestedUpdateOperationsFields?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Field Level Aggregations Where", () => {
typeMovie = testHelper.createUniqueType("Movie");
typePerson = testHelper.createUniqueType("Person");

typeDefs = `
typeDefs = /* GraphQL */ `
type ${typeMovie.name} @node {
title: String
actors: [${typePerson.name}!]! @relationship(type: "ACTED_IN", direction: IN, properties:"ActedIn")
Expand Down Expand Up @@ -61,7 +61,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes where string equals", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {name_EQ: "Linda"}) {
Expand All @@ -80,7 +80,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with OR query", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {OR: [{name_EQ: "Linda"}, {name_EQ: "Arnold"}]}) {
Expand All @@ -99,7 +99,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with nested aggregation", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {moviesAggregate: { count_EQ: 1}}) {
Expand All @@ -117,10 +117,10 @@ describe("Field Level Aggregations Where", () => {

describe("Using connections in where", () => {
test("Count nodes with where in connection node", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typePerson.plural} {
moviesAggregate(where:{actorsConnection: { node: { name_EQ: "Linda" } }}){
moviesAggregate(where:{actorsConnection_SOME: { node: { name_EQ: "Linda" } }}){
count
}
}
Expand All @@ -134,10 +134,10 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with where in connection edge", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typePerson.plural} {
moviesAggregate(where:{actorsConnection: {edge: {screentime_GT: 10}}}){
moviesAggregate(where:{actorsConnection_SOME: {edge: {screentime_GT: 10}}}){
count
}
}
Expand All @@ -151,10 +151,10 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with where in connection node using OR", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typePerson.plural} {
moviesAggregate(where:{actorsConnection: {node: {OR: [{ name_EQ: "Linda" },{ name_EQ: "Arnold" } ]}}}){
moviesAggregate(where:{actorsConnection_SOME: {node: {OR: [{ name_EQ: "Linda" },{ name_EQ: "Arnold" } ]}}}){
count
}
}
Expand All @@ -169,7 +169,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with where using IN strings", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {name_IN: ["Linda", "Arnold"]}) {
Expand All @@ -188,7 +188,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with where using IN ints", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {age_IN: [40, 60, 37]}) {
Expand All @@ -207,7 +207,7 @@ describe("Field Level Aggregations Where", () => {
});

test("Count nodes with datetime filter", async () => {
const query = `
const query = /* GraphQL */ `
query {
${typeMovie.plural} {
actorsAggregate(where: {born_GT: "2000-01-01"}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Connections Filtering", () => {
const query = `
query ($movieTitle: String!) {
${movieType.plural}(where: { title_EQ: $movieTitle }) {
actorsConnection(where: {node: {movies: { title_EQ: $movieTitle } } }) {
actorsConnection(where: {node: {movies_SOME: { title_EQ: $movieTitle } } }) {
edges {
node {
name
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("Connections Filtering", () => {

const query = `
query {
${movieType.plural} (where: {actorsConnection: { OR: [{ node: { name_EQ: "${actor1Name}" } }, { node: { name_EQ: "${actor2Name}" } }]}}){
${movieType.plural} (where: {actorsConnection_SOME: { OR: [{ node: { name_EQ: "${actor1Name}" } }, { node: { name_EQ: "${actor2Name}" } }]}}){
actorsConnection {
edges {
node {
Expand Down Expand Up @@ -151,7 +151,7 @@ describe("Connections Filtering", () => {

const query = `
query {
${movieType.plural} (where: {actorsConnection: { NOT: { node: { name_EQ: "${actor1Name}" } } } }){
${movieType.plural} (where: {actorsConnection_SOME: { NOT: { node: { name_EQ: "${actor1Name}" } } } }){
actorsConnection {
edges {
node {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/tests/integration/delete.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ describe("delete", () => {

const mutation = `
mutation($name: String) {
${Movie.operations.delete}(where: { actorsConnection: { node: { name_EQ: $name } } } ) {
${Movie.operations.delete}(where: { actorsConnection_SOME: { node: { name_EQ: $name } } } ) {
nodesDeleted
relationshipsDeleted
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("field-filtering", () => {
{
${Movie.plural}(where: { title_EQ: "${movieTitle}" }) {
title
genres(where: { seriesConnection: { node: { name_EQ: "${seriesName}" } } }) {
genres(where: { seriesConnection_SOME: { node: { name_EQ: "${seriesName}" } } }) {
name
series {
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ describe("Advanced Filtering", () => {

const query = `
{
${randomType1.plural}(where: { ${randomType2.plural}: { id_EQ: "${relationId}" } }) {
${randomType1.plural}(where: { ${randomType2.plural}_SOME: { id_EQ: "${relationId}" } }) {
id
${randomType2.plural} {
id
Expand Down Expand Up @@ -1111,7 +1111,7 @@ describe("Advanced Filtering", () => {

const query = `
{
${Movie.plural}(where: { genresConnection: { node: { id_EQ: "${genreId}" } } }) {
${Movie.plural}(where: { genresConnection_SOME: { node: { id_EQ: "${genreId}" } } }) {
id
genres {
id
Expand Down Expand Up @@ -1176,7 +1176,7 @@ describe("Advanced Filtering", () => {

const query = `
{
${Movie.plural}(where: { genresConnection: { edge: { id_EQ: "${actedInId}" } } }) {
${Movie.plural}(where: { genresConnection_SOME: { edge: { id_EQ: "${actedInId}" } } }) {
id
genres {
id
Expand Down Expand Up @@ -1240,7 +1240,7 @@ describe("Advanced Filtering", () => {

const query = `
{
${Movie.plural}(where: { genresConnection: { node: { id_EQ: "${genreId}" } edge: { id_EQ: "${actedInId}" } } }) {
${Movie.plural}(where: { genresConnection_SOME: { node: { id_EQ: "${genreId}" } edge: { id_EQ: "${actedInId}" } } }) {
id
genres {
id
Expand Down Expand Up @@ -1310,7 +1310,7 @@ describe("Advanced Filtering", () => {

const query = /* GraphQL */ `
{
${randomType1.plural}(where: { NOT: { ${randomType2.plural}: { id_EQ: "${relationId2}" } } }) {
${randomType1.plural}(where: { NOT: { ${randomType2.plural}_SOME: { id_EQ: "${relationId2}" } } }) {
id
${randomType2.plural} {
id
Expand Down Expand Up @@ -1842,7 +1842,7 @@ describe("Advanced Filtering", () => {

const nullQuery = `
{
${randomType1.plural}(where: { ${randomType2.plural}: null }) {
${randomType1.plural}(where: { ${randomType2.plural}_SOME: null }) {
id
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("interface relationships aliased fields", () => {
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
type ${ProtectedActor} @node @authorization(validate: [{ where: { node: { actedInConnection: { node: { title_EQ: "$jwt.title" } } } } }]) {
type ${ProtectedActor} @node @authorization(validate: [{ where: { node: { actedInConnection_SOME: { node: { title_EQ: "$jwt.title" } } } } }]) {
name: String! @alias(property: "dbName")
actedIn: [Production!]! @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("Single relationship (1-*) filtering", () => {
const query = `
query {
${Person.plural}(
where: { actedIn: { OR: [{ director: { name_EQ: "Jon Wu" } }, { producer: { name_EQ: "Jon Wu" } }] } }
where: { actedIn_SOME: { OR: [{ director: { name_EQ: "Jon Wu" } }, { producer: { name_EQ: "Jon Wu" } }] } }
) {
name
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ describe("type narrowing - simple case", () => {

const query = /* GraphQL */ `
query People {
people(where: { actedInConnection: { edge: { ActedIn: { screenTime_EQ: ${movieScreenTime} }, AppearsIn: { sceneNr_EQ: ${sceneNr} } } } }) {
people(where: { actedInConnection_SOME: { edge: { ActedIn: { screenTime_EQ: ${movieScreenTime} }, AppearsIn: { sceneNr_EQ: ${sceneNr} } } } }) {
name
actedInConnection {
edges {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/tests/integration/issues/1628.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("https://github.com/neo4j/graphql/issues/1628", () => {
test("Nested filter with limit cypher should be composed correctly", async () => {
const query = /* GraphQL */ `
{
${workType.plural}(limit: 1, where: { title: { value_CONTAINS: "0777" } }) {
${workType.plural}(limit: 1, where: { title_SOME: { value_CONTAINS: "0777" } }) {
title(where: { value_CONTAINS: "0777" }) {
value
}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/tests/integration/issues/190.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("https://github.com/neo4j/graphql/issues/190", () => {
test("Example 1", async () => {
const query = /* GraphQL */ `
query {
${User.plural}(where: { demographics: { type_EQ: "Gender", value_EQ: "Female" } }) {
${User.plural}(where: { demographics_SOME: { type_EQ: "Gender", value_EQ: "Female" } }) {
uid
demographics {
type
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("https://github.com/neo4j/graphql/issues/190", () => {
query {
${User.plural}(
where: {
demographics: { OR: [{ type_EQ: "Gender", value_EQ: "Female" }, { type_EQ: "State" }, { type_EQ: "Age" }] }
demographics_SOME: { OR: [{ type_EQ: "Gender", value_EQ: "Female" }, { type_EQ: "State" }, { type_EQ: "Age" }] }
}
) {
uid
Expand Down
Loading

0 comments on commit 8832dd6

Please sign in to comment.