Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions __tests__/__snapshots__/fulltext.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GraphQLSchema {
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
Expand All @@ -61,6 +62,7 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -105,6 +107,7 @@ GraphQLSchema {
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
Expand All @@ -125,6 +128,73 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

exports[`fulltext search field is created and working with language 1`] = `
GraphQLSchema {
"__allowedLegacyNames": Array [],
"__validationErrors": undefined,
"_directives": Array [
"@include",
"@skip",
"@deprecated",
],
"_implementations": Object {
"Node": Array [
"Query",
"Job",
],
},
"_mutationType": "Mutation",
"_possibleTypeMap": Object {},
"_queryType": "Query",
"_subscriptionType": undefined,
"_typeMap": Object {
"Boolean": "Boolean",
"CreateJobInput": "CreateJobInput",
"CreateJobPayload": "CreateJobPayload",
"Cursor": "Cursor",
"DeleteJobByIdInput": "DeleteJobByIdInput",
"DeleteJobInput": "DeleteJobInput",
"DeleteJobPayload": "DeleteJobPayload",
"Float": "Float",
"FullText": "FullText",
"FullTextFilter": "FullTextFilter",
"ID": "ID",
"Int": "Int",
"IntFilter": "IntFilter",
"Job": "Job",
"JobCondition": "JobCondition",
"JobFilter": "JobFilter",
"JobInput": "JobInput",
"JobPatch": "JobPatch",
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
"Query": "Query",
"String": "String",
"StringFilter": "StringFilter",
"UpdateJobByIdInput": "UpdateJobByIdInput",
"UpdateJobInput": "UpdateJobInput",
"UpdateJobPayload": "UpdateJobPayload",
"__Directive": "__Directive",
"__DirectiveLocation": "__DirectiveLocation",
"__EnumValue": "__EnumValue",
"__Field": "__Field",
"__InputValue": "__InputValue",
"__Schema": "__Schema",
"__Type": "__Type",
"__TypeKind": "__TypeKind",
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -169,6 +239,7 @@ GraphQLSchema {
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
Expand All @@ -189,6 +260,7 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -233,6 +305,7 @@ GraphQLSchema {
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
Expand All @@ -253,6 +326,7 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -297,6 +371,7 @@ GraphQLSchema {
"JobsConnection": "JobsConnection",
"JobsEdge": "JobsEdge",
"JobsOrderBy": "JobsOrderBy",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"PageInfo": "PageInfo",
Expand All @@ -317,6 +392,7 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -368,6 +444,7 @@ GraphQLSchema {
"ID": "ID",
"Int": "Int",
"IntFilter": "IntFilter",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"Order": "Order",
Expand Down Expand Up @@ -399,6 +476,7 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;

Expand Down Expand Up @@ -450,6 +528,7 @@ GraphQLSchema {
"ID": "ID",
"Int": "Int",
"IntFilter": "IntFilter",
"MatchInput": "MatchInput",
"Mutation": "Mutation",
"Node": "Node",
"Order": "Order",
Expand Down Expand Up @@ -481,5 +560,6 @@ GraphQLSchema {
},
"astNode": undefined,
"extensionASTNodes": undefined,
"extensions": undefined,
}
`;
96 changes: 87 additions & 9 deletions __tests__/fulltext.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test(
allJobs(
filter: {
fullText: {
matches: "fruit"
matches: { value: "fruit" }
}
}
orderBy: [
Expand Down Expand Up @@ -81,7 +81,7 @@ test(
allJobs(
filter: {
fullText: {
matches: "banana"
matches: { value: "banana" }
}
}
) {
Expand Down Expand Up @@ -140,6 +140,84 @@ test(
}),
);

test(
'fulltext search field is created and working with language',
withSchema({
setup: `
create table fulltext_test.job (
id serial primary key,
name text not null,
full_text tsvector,
other_full_text tsvector
);
insert into fulltext_test.job (name, full_text, other_full_text) values
('test', to_tsvector('italian', 'apple fruit'), to_tsvector('italian', 'vegetable potato')),
('test 2', to_tsvector('italian', 'banana fruit'), to_tsvector('italian', 'vegetable pumpkin'));
`,
test: async ({ schema, pgClient }) => {
const query = `
query {
allJobs(
filter: {
fullText: {
matches: { language: "italian", value: "fruit" }
}
otherFullText: {
matches: { language: "italian", value: "vegetable" }
}
}
orderBy: [
FULL_TEXT_RANK_ASC
OTHER_FULL_TEXT_DESC
]
) {
nodes {
id
name
fullTextRank
otherFullTextRank
}
}
}
`;
expect(schema).toMatchSnapshot();

const result = await graphql(schema, query, null, { pgClient });
expect(result).not.toHaveProperty('errors');

const data = result.data.allJobs.nodes;
expect(data).toHaveLength(2);
data.map(n => expect(n.fullTextRank).not.toBeNull());
data.map(n => expect(n.otherFullTextRank).not.toBeNull());

const potatoQuery = `
query {
allJobs(
filter: {
otherFullText: {
matches: { language: "italian", value: "potato" }
}
}
) {
nodes {
id
name
fullTextRank
otherFullTextRank
}
}
}
`;
const potatoResult = await graphql(schema, potatoQuery, null, { pgClient });
expect(potatoResult).not.toHaveProperty('errors');

const potatoData = potatoResult.data.allJobs.nodes;
expect(potatoData).toHaveLength(1);
potatoData.map(n => expect(n.fullTextRank).toBeNull());
potatoData.map(n => expect(n.otherFullTextRank).not.toBeNull());
},
}),
);
test(
'fulltext search field is created',
withSchema({
Expand All @@ -160,10 +238,10 @@ test(
allJobs(
filter: {
fullText: {
matches: "fruit"
matches: { value: "fruit" }
}
otherFullText: {
matches: "vegetable"
matches: { value: "vegetable" }
}
}
orderBy: [
Expand Down Expand Up @@ -195,7 +273,7 @@ test(
allJobs(
filter: {
otherFullText: {
matches: "potato"
matches: { value: "potato" }
}
}
) {
Expand Down Expand Up @@ -238,7 +316,7 @@ test(
allJobs(
filter: {
fullText: {
matches: "fruit | banana"
matches: { value: "fruit | banana" }
}
}
orderBy: $orderBy
Expand Down Expand Up @@ -304,7 +382,7 @@ test(
allOrders(filter: {
or: [
{ comment: { includes: "Z"} },
{ clientByClientId: { tsv: { matches: "apple" } } }
{ clientByClientId: { tsv: { matches: { value: "apple" } } } }
]
}) {
nodes {
Expand Down Expand Up @@ -348,7 +426,7 @@ test(
comment text,
tsv tsvector
);

insert into fulltext_test.clients (id, comment, tsv) values
(1, 'Client A', tsvector('fruit apple')),
(2, 'Client Z', tsvector('fruit avocado'));
Expand All @@ -365,7 +443,7 @@ test(
const query = `
query {
allOrders(filter: {
clientByClientId: { tsv: { matches: "avocado" } }
clientByClientId: { tsv: { matches: { value: "avocado" } } }
}) {
nodes {
id
Expand Down
Loading