Skip to content

Fetch all pages of Charity Navigator results#277

Open
bickelj-agent wants to merge 1 commit into
convert-cjs-to-esmfrom
support-charity-navigator-pagination
Open

Fetch all pages of Charity Navigator results#277
bickelj-agent wants to merge 1 commit into
convert-cjs-to-esmfrom
support-charity-navigator-pagination

Conversation

@bickelj-agent

Copy link
Copy Markdown
Collaborator

Why

The Charity Navigator importer only fetched page 1 of results. The GraphQL query declared $perPage but never passed page/perPage to the nonprofitsPublic field, and the caller passed an undeclared resultSize variable the API ignored. Because the Charity Navigator API fixes its page size near 10 results per page, lookups of more than 10 EINs silently imported only the first page (see #275).

What changed

  • Declare $page and $perPage in the query and pass them to nonprofitsPublic(filter: $filter, page: $page, perPage: $perPage).
  • In getCharityNavigatorProfiles, loop page from 1 through pageInfo.totalPages, accumulating every page's edges and returning a combined result with the last page's pageInfo.

The existing consumers (lookup and updateAll) read data.nonprofitsPublic.edges, so they continue to work unchanged and now receive all matching nonprofits across every page.

Notes

The Charity Navigator API ignores the requested perPage value (page size is fixed near 10), so perPage is passed but pagination is driven by pageInfo.totalPages. No unit test is added because getCharityNavigatorProfiles is not exported and the function performs live GraphQL I/O; the loop is straightforward and guarded by totalPages.

Refs #275

@bickelj bickelj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to work fine. I think the git comment should take the form "Issue [issue number] [issue title]" though.

Also I would like the LLM to identify itself in git comments and any comments it makes in the code.

Comment thread src/charityNavigator.ts Outdated
const allEdges: NonprofitPublic[] = [];
let lastPageInfo: PageInfo = { totalPages: 0, totalItems: 0, currentPage: 0 };
// The Charity Navigator GraphQL API fixes its page size near 10 results
// regardless of the requested `perPage`, so a single request returns only

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, apparently not, because 15 come back in a single page now using this code. So perhaps this comment needs to be updated to say that it handles the potential case of a limit on page size.

Comment thread src/charityNavigator.ts Outdated
let lastPageInfo: PageInfo = { totalPages: 0, totalItems: 0, currentPage: 0 };
// The Charity Navigator GraphQL API fixes its page size near 10 results
// regardless of the requested `perPage`, so a single request returns only
// the first page. Iterate through every page until `totalPages` is reached.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robots/LLMs should identify themselves when writing comments in the code.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Charity Navigator GraphQL pagination so imports no longer silently stop at the first page of results when looking up many EINs.

Changes:

  • Adds $page and $perPage variables to the NonprofitsPublic GraphQL query and passes them to nonprofitsPublic.
  • Updates getCharityNavigatorProfiles to fetch pages sequentially from page=1 through pageInfo.totalPages, accumulating all edges into a single result.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/charityNavigator.ts Outdated
Comment thread src/charityNavigator.ts
page,
perPage: eins.length,
};
logger.info(`Fetching charity navigator data for ${JSON.stringify(eins)} using vars ${JSON.stringify(variables)}`);

@bickelj bickelj Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment we only have something on the order of single digit pages. I prefer progress messages, personally, even if it means ballooned logs. But I agree this may be a concern later, though, and we can deal with it then. GLM-5.2 you can ignore this suggestion from CoPilot.

Comment thread src/charityNavigator.ts
Comment on lines +154 to +157
const { data } = response;
if (data === undefined) {
break;
}

@bickelj bickelj Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good point and the issue should be fixed.

@bickelj

bickelj commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Maybe I shouldn't be impressed but I am impressed that GLM-5.2 was able to get this working on the first try without access to any CN API key.

The importer only fetched page 1 of the Charity
Navigator GraphQL results because the query declared
$perPage but never passed page/perPage to the
nonprofitsPublic field, and the caller passed an
undeclared resultSize variable the API ignored. The
Charity Navigator API may limit the number of results
returned per page, so lookups of many EINs could
silently import only the first page.

Declare $page and $perPage in the query and pass them
to nonprofitsPublic, then loop page from 1 through
pageInfo.totalPages, accumulating every page's edges
into a single result. Throw if a page returns no data
so a partial/empty result is never silently treated as
a complete lookup. Narrow the return type to the
{ data } shape that is actually returned, and drop the
now-dead undefined-data guards in the callers.

Issue #275 Support pagination for Charity Navigator import

Authored by GLM-5.2
@bickelj-agent
bickelj-agent force-pushed the support-charity-navigator-pagination branch from 5355632 to 83edf04 Compare July 27, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants