Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

improve query ergonomics #31

Closed
wants to merge 13 commits into from
82 changes: 48 additions & 34 deletions integration-tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as orgsWithGrants from './test-queries/orgs-with-grants';
import * as someNews from './test-queries/some-news';
import * as boardTerms from './test-queries/board-terms';
import * as moreMeta from './test-queries/more-meta';
import * as orgNameLike from './test-queries/org-name-like';
import * as sortOrgGrantsByDate from './test-queries/sort-org-grants-by-date';

const createServerInstance = async () => {
const db = dbFactory();
Expand Down Expand Up @@ -67,13 +69,13 @@ test('organization_meta updates automatically', async () => {
const { uri, instance, db } = await createServerInstance();
const query = `
query foo {
giver: organizationMetas(id: 3) {
giver: organization(id: 3) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
}
receiver: organizationMetas(id: 91) {
receiver: organization(id: 91) {
countGrantsTo
countGrantsFrom
countDistinctFunders
Expand All @@ -98,41 +100,53 @@ query foo {

// Assert
expect(resBefore).toEqual({
giver: [
{
countGrantsTo: 0,
countGrantsFrom: 0,
countDistinctFunders: 0,
countDistinctRecipients: 0,
},
],
receiver: [
{
countGrantsTo: 17,
countGrantsFrom: 17,
countDistinctFunders: 17,
countDistinctRecipients: 17,
},
],
giver: {
countGrantsTo: 0,
countGrantsFrom: 0,
countDistinctFunders: 0,
countDistinctRecipients: 0,
},
receiver: {
countGrantsTo: 17,
countGrantsFrom: 17,
countDistinctFunders: 17,
countDistinctRecipients: 17,
},
});
expect(resAfter).toEqual({
giver: [
{
countGrantsTo: 0,
countGrantsFrom: 1,
countDistinctFunders: 0,
countDistinctRecipients: 1,
},
],
receiver: [
{
countGrantsTo: 18,
countGrantsFrom: 17,
countDistinctFunders: 18,
countDistinctRecipients: 17,
},
],
giver: {
countGrantsTo: 0,
countGrantsFrom: 1,
countDistinctFunders: 0,
countDistinctRecipients: 1,
},
receiver: {
countGrantsTo: 18,
countGrantsFrom: 17,
countDistinctFunders: 18,
countDistinctRecipients: 17,
},
});

instance.close();
});

test('filters organizations by name', async () => {
const { uri, instance } = await createServerInstance();

const res = await request(uri, orgNameLike.query);

expect(res).toEqual(orgNameLike.expected.data);

instance.close();
});

test('sorts organization grants by date', async () => {
const { uri, instance } = await createServerInstance();

const res = await request(uri, sortOrgGrantsByDate.query);

expect(res).toEqual(sortOrgGrantsByDate.expected.data);

instance.close();
});
19 changes: 7 additions & 12 deletions integration-tests/test-queries/more-meta.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
export const query = `
query foo {
organizationMetas(
organizations(
limit: 2
offset: 1
orderByMulti: [["countGrantsTo", "DESC"], ["id", "ASC"]]
orderBy: countGrantsTo
orderByDirection: DESC
) {
countGrantsTo
countGrantsFrom
countDistinctFunders
countDistinctRecipients
organization {
name
}
name
}
}
`;

export const expected = {
data: {
organizationMetas: [
organizations: [
{
countGrantsTo: 16,
countGrantsFrom: 16,
countDistinctFunders: 16,
countDistinctRecipients: 16,
organization: {
name: 'test organization 89',
},
name: 'test organization 89',
},
{
countGrantsTo: 16,
countGrantsFrom: 16,
countDistinctFunders: 16,
countDistinctRecipients: 16,
organization: {
name: 'test organization 91',
},
name: 'test organization 91',
},
],
},
Expand Down
25 changes: 25 additions & 0 deletions integration-tests/test-queries/org-name-like.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export const query = `
query orgNameLike {
organizations(nameLike: "%organization 9%", limit: 11) {
name
}
}
`;

export const expected = {
data: {
organizations: [
{ name: 'test organization 9' },
{ name: 'test organization 90' },
{ name: 'test organization 91' },
{ name: 'test organization 92' },
{ name: 'test organization 93' },
{ name: 'test organization 94' },
{ name: 'test organization 95' },
{ name: 'test organization 96' },
{ name: 'test organization 97' },
{ name: 'test organization 98' },
{ name: 'test organization 99' },
],
},
};
Loading