Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Commit

Permalink
Add failing test for nested relationship type filter bug
Browse files Browse the repository at this point in the history
See #281
  • Loading branch information
johnymontana committed Aug 28, 2019
1 parent 203736f commit 14dd3ce
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions test/unit/filterTest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import test from 'ava';
import { makeAugmentedSchema, cypherQuery } from '../../src/index.js';
import { graphql } from 'graphql';

test('Filters with unfiltered parents, nested relationship types', async t => {
const typeDefs = /* GraphQL */ `
type A_B_Relation @relation(name: "A_TO_B") {
from: A
to: B
}
type B_C_Relation @relation(name: "B_TO_C") {
from: B
to: C
active: Boolean!
}
type A {
bArray: [A_B_Relation!]!
}
type B {
cArray: [B_C_Relation!]!
}
type C {
id: ID!
}
type Query {
A: [A]
}
`;

const graphqlQuery = /* GraphQL */ `
{
A {
bArray {
B {
filteredCArray: cArray(filter: { active: true }) {
C {
id
}
}
}
}
}
}
`;

const expectedCypherQuery =
'MATCH (`a`:`A`) RETURN `a` {bArray: [(`a`)-[`a_bArray_relation`:`A_TO_B`]->(:`B`) | a_bArray_relation {B: head([(:`A`)-[`a_bArray_relation`]->(`a_bArray_B`:`B`) | a_bArray_B {cArray: [(`a_bArray_B`)-[`a_bArray_B_cArray_relation`:`B_TO_C`]->(:`C`) WHERE (`a_bArray_B_cArray_relation`.active = $1_filter.active) | a_bArray_B_cArray_relation {C: head([(:`B`)-[`a_bArray_B_cArray_relation`]->(`a_bArray_B_cArray_C`:`C`) | a_bArray_B_cArray_C { .id }]) }] }]) }] } AS `a`';
const expectedCypherParams = {
'1_filter': { active: true },
first: -1,
offset: 0
};

const resolvers = {
Query: {
A(object, params, ctx, resolveInfo) {
const [query, queryParams] = cypherQuery(params, ctx, resolveInfo);
t.is(query, expectedCypherQuery);
t.deepEqual(queryParams, expectedCypherParams);
return [];
}
}
};

const schema = makeAugmentedSchema({
typeDefs,
resolvers,
config: { mutation: false }
});

// query the test schema with the test query, assertion is in the resolver
const resp = await graphql(schema, graphqlQuery);

t.deepEqual(resp.data.A, []);

return;
});

0 comments on commit 14dd3ce

Please sign in to comment.