Skip to content

Commit 0c56023

Browse files
committed
test: add test case for issue 304
related #304
1 parent f958dcc commit 0c56023

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { SchemaComposer, graphql } from 'graphql-compose';
2+
import { composeMongoose } from '../../index';
3+
import { mongoose } from '../../__mocks__/mongooseCommon';
4+
import { Document } from 'mongoose';
5+
6+
const schemaComposer = new SchemaComposer<{ req: any }>();
7+
8+
// mongoose.set('debug', true);
9+
10+
const OrderSchema = new mongoose.Schema({
11+
orderStatus: String,
12+
inbound: {
13+
timeStamp: {
14+
type: Date,
15+
index: true,
16+
},
17+
},
18+
});
19+
20+
interface IOrder extends Document {
21+
orderStatus?: string;
22+
inbound?: {
23+
timeStamp?: Date | null;
24+
};
25+
}
26+
27+
const OrderModel = mongoose.model<IOrder>('Order', OrderSchema);
28+
const OrderTC = composeMongoose(OrderModel, { schemaComposer });
29+
30+
schemaComposer.Query.addFields({
31+
orderMany: OrderTC.mongooseResolvers.findMany({
32+
suffix: 'Extended',
33+
filter: {
34+
operators: true,
35+
},
36+
}),
37+
});
38+
39+
const schema = schemaComposer.buildSchema();
40+
41+
beforeAll(async () => {
42+
await OrderModel.base.createConnection();
43+
await OrderModel.create([
44+
{ orderStatus: 'PAID', inbound: { timeStamp: null } },
45+
{ orderStatus: 'PAID', inbound: { timeStamp: 123 } },
46+
{ orderStatus: 'UNPAID', inbound: { timeStamp: null } },
47+
{ orderStatus: 'UNPAID', inbound: { timeStamp: 456 } },
48+
]);
49+
});
50+
afterAll(() => {
51+
OrderModel.base.disconnect();
52+
});
53+
54+
describe('issue #304 - Filter _operator for nested fields not apply', () => {
55+
it('check runtime', async () => {
56+
const result = await graphql.graphql({
57+
schema,
58+
source: `query {
59+
orderMany(filter: {
60+
_operators: {
61+
inbound: { timeStamp: { ne: null } }
62+
orderStatus: { ne: "PAID" }
63+
}
64+
}) {
65+
orderStatus
66+
inbound {
67+
timeStamp
68+
}
69+
}
70+
}`,
71+
});
72+
expect(result).toEqual({
73+
data: {
74+
orderMany: [{ inbound: { timeStamp: '1970-01-01T00:00:00.456Z' }, orderStatus: 'UNPAID' }],
75+
},
76+
});
77+
});
78+
});

0 commit comments

Comments
 (0)