/**
* GraphQL queries and fragments
*/
import { gql } from '@apollo/client';
// ============================================
// Fragments
// ============================================
export const MP_BASIC_FRAGMENT = gql`
fragment MPBasic on MP {
id
name
party
riding
current
cabinet_position
photo_url
photo_url_source
}
`;
export const MP_SEATING_FRAGMENT = gql`
fragment MPSeating on MP {
id
name
party
riding
current
cabinet_position
parl_mp_id
seat_row
seat_column
bench_section
seat_visual_x
seat_visual_y
}
`;
export const MP_FULL_FRAGMENT = gql`
fragment MPFull on MP {
...MPBasic
gender
elected_date
email
phone
twitter
wikipedia_id
constituency_office
ourcommons_url
memberOf {
code
name
seats
}
represents {
name
province
}
}
${MP_BASIC_FRAGMENT}
`;
export const BILL_BASIC_FRAGMENT = gql`
fragment BillBasic on Bill {
number
session
title
title_fr
summary
summary_fr
status
status_fr
bill_type
bill_type_fr
is_government_bill
originating_chamber
originating_chamber_fr
introduced_date
}
`;
export const STATEMENT_FRAGMENT = gql`
fragment StatementBasic on Statement {
id
# time field removed - causes APOC date parsing error with ISO strings
who_en
who_fr
content_en
content_fr
h1_en
h1_fr
h2_en
h2_fr
h3_en
h3_fr
statement_type
wordcount
procedural
thread_id
parent_statement_id
sequence_in_thread
}
`;
// ============================================
// MP Queries
// ============================================
export const GET_MPS = gql`
query GetMPs($where: MPWhere, $options: MPOptions) {
mps(where: $where, options: $options) {
...MPBasic
}
}
${MP_BASIC_FRAGMENT}
`;
export const SEARCH_MPS = gql`
query SearchMPs($searchTerm: String, $party: String, $current: Boolean, $cabinetOnly: Boolean, $limit: Int) {
searchMPs(searchTerm: $searchTerm, party: $party, current: $current, cabinetOnly: $cabinetOnly, limit: $limit) {
...MPBasic
}
}
${MP_BASIC_FRAGMENT}
`;
// Optimized paginated MPs query with offset-based pagination
export const PAGINATED_MPS = gql`
query PaginatedMPs($parties: [String!], $current: Boolean, $cabinetOnly: Boolean, $searchTerm: String, $limit: Int, $offset: Int) {
paginatedMPs(parties: $parties, current: $current, cabinetOnly: $cabinetOnly, searchTerm: $searchTerm, limit: $limit, offset: $offset) {
...MPBasic
}
}
${MP_BASIC_FRAGMENT}
`;
// Count MPs matching filters
export const COUNT_MPS = gql`
query CountMPs($parties: [String!], $current: Boolean, $cabinetOnly: Boolean, $searchTerm: String) {
countMPs(parties: $parties, current: $current, cabinetOnly: $cabinetOnly, searchTerm: $searchTerm) {
count
}
}
`;
export const GET_CHAMBER_SEATING = gql`
query GetChamberSeating {
mps(where: { current: true, seat_row_NOT: null }) {
...MPSeating
}
}
${MP_SEATING_FRAGMENT}
`;
// Optimized: Minimal query for MP page initial load (header + overview only)
export const GET_MP_BASIC_INFO = gql`
query GetMPBasicInfo($id: ID!) {
mps(where: { id: $id }) {
...MPFull
votedConnection(first: 5, sort: [{ node: { date: DESC } }]) {
edges {
properties {
position
}
node {
id
number
date
result
yeas
nays
description
subjectOf {
number
title
session
}
}
}
}
}
}
${MP_FULL_FRAGMENT}
`;
// Legacy full query - kept for backward compatibility
export const GET_MP = gql`
query GetMP($id: ID!) {
mps(where: { id: $id }) {
...MPFull
sponsored(options: { limit: 100, sort: [{ introduced_date: DESC }] }) {
...BillBasic
}
expenses(options: { limit: 50, sort: [{ fiscal_year: DESC }, { quarter: DESC }] }) {
id
fiscal_year
quarter
amount
category
description
}
votedConnection(first: 20, sort: [{ node: { date: DESC } }]) {
edges {
properties {
position
}
node {
id
number
date
result
yeas
nays
description
subjectOf {
number
title
session
}
}
}
}
servedOnConnection {
edges {
properties {
role
}
node {
code
name
mandate
chamber
}
}
}
metWithConnection(
first: 20
sort: [{ edge: { last_contact: DESC } }]
) {
totalCount
edges {
properties {
first_contact
last_contact
}
node {
id
name
firm
worksFor {
id
name
industry
}
}
}
}
}
}
${MP_FULL_FRAGMENT}
${BILL_BASIC_FRAGMENT}
`;
// Lazy-loaded tab-specific queries
export const GET_MP_LEGISLATION = gql`
query GetMPLegislation($id: ID!) {
mps(where: { id: $id }) {
id
sponsored(options: { limit: 100, sort: [{ introduced_date: DESC }] }) {
...BillBasic
}
}
}
${BILL_BASIC_FRAGMENT}
`;
export const GET_MP_EXPENSES = gql`
query GetMPExpenses($id: ID!) {
mps(where: { id: $id }) {
id
expenses(options: { limit: 50, sort: [{ fiscal_year: DESC }, { quarter: DESC }] }) {
id
fiscal_year
quarter
amount
category
description
}
}
}
`;
export const GET_MP_VOTES = gql`
query GetMPVotes($id: ID!) {
mps(where: { id: $id }) {
id
votedConnection(first: 100, sort: [{ node: { date: DESC } }]) {
edges {
properties {
position
}
node {
id
number
date
result
yeas
nays
description
subjectOf {
number
title
session
}
}
}
}
}
}
`;
export const GET_MP_COMMITTEES = gql`
query GetMPCommittees($id: ID!) {
mps(where: { id: $id }) {
id
servedOnConnection {
edges {
properties {
role
}
node {
code
name
mandate
chamber
}
}
}
}
}
`;
export const GET_MP_SCORECARD = gql`
query GetMPScorecard($mpId: ID!) {
mpScorecard(mpId: $mpId) {
mp {
id
name
given_name
family_name
party
riding
current
cabinet_position
email
phone
updated_at
}
bills_sponsored
bills_passed
votes_participated
petitions_sponsored
total_petition_signatures
current_year_expenses
lobbyist_meetings
question_period_interjections
voting_participation_rate
party_discipline_score
legislative_success_rate
committee_activity_index
}
}
`;
// TODO: Re-enable when GlobalExpenseStats type is implemented in graph-api schema
// export const GET_GLOBAL_EXPENSE_STATS = gql`
// query GetGlobalExpenseStats {
// globalExpenseStats {
// average_per_quarter
// median_per_quarter
// total_quarters
// }
// }
// `;
export const GET_MP_NEWS = gql`
query GetMPNews($mpName: String!, $limit: Int = 10) {
mpNews(mpName: $mpName, limit: $limit) {
title
url
source
published_date
description
image_url
last_updated
}
}
`;
// ============================================
// Bill Queries
// ============================================
export const GET_BILLS = gql`
query GetBills($where: BillWhere, $options: BillOptions) {
bills(where: $where, options: $options) {
...BillBasic
sponsor {
id
name
party
}
}
}
${BILL_BASIC_FRAGMENT}
`;
export const SEARCH_BILLS = gql`
query SearchBills(
$searchTerm: String
$status: String
$session: String
$bill_type: String
$is_government_bill: Boolean
$originating_chamber: String
$limit: Int
) {
searchBills(
searchTerm: $searchTerm
status: $status
session: $session
bill_type: $bill_type
is_government_bill: $is_government_bill
originating_chamber: $originating_chamber
limit: $limit
) {
...BillBasic
sponsor {
name
party
}
}
}
${BILL_BASIC_FRAGMENT}
`;
export const GET_BILL = gql`
query GetBill($number: String!, $session: String!) {
bills(where: { number: $number, session: $session }) {
...BillBasic
summary
summary_fr
stage
latest_event
passed_date
royal_assent_date
# Reading stage dates
passed_house_first_reading
passed_house_second_reading
passed_house_third_reading
passed_senate_first_reading
passed_senate_second_reading
passed_senate_third_reading
# Statute info
statute_year
statute_chapter
# Full narrative text
full_text_en
full_text_fr
full_text_updated_at
# Committees
referredTo {
code
name
}
sponsor {
...MPBasic
}
votes(options: { limit: 25, sort: [{ date: DESC }] }) {
id
date
result
description
yeas
nays
}
}
}
${BILL_BASIC_FRAGMENT}
${MP_BASIC_FRAGMENT}
`;
// Find the latest version of a bill by number (across all sessions)
// Returns bills sorted by session descending, so first result is most recent
export const GET_LATEST_BILL_BY_NUMBER = gql`
query GetLatestBillByNumber($number: String!) {
bills(
where: { number: $number }
options: { sort: [{ session: DESC }], limit: 1 }
) {
...BillBasic
parliament
summary
summary_fr
stage
latest_event
passed_date
royal_assent_date
passed_house_first_reading
passed_house_second_reading
passed_house_third_reading
passed_senate_first_reading
passed_senate_second_reading
passed_senate_third_reading
statute_year
statute_chapter
full_text_en
full_text_fr
full_text_updated_at
referredTo {
code
name
}
sponsor {
...MPBasic
}
}
}
${BILL_BASIC_FRAGMENT}
${MP_BASIC_FRAGMENT}
`;
export const GET_BILL_LOBBYING = gql`
query GetBillLobbying($billNumber: String!, $session: String!) {
billLobbying(billNumber: $billNumber, session: $session) {
bill_number
bill_session
bill_title
bill_status
organizations_lobbying
total_lobbying_events
organizations {
name
industry
lobbying_count
}
communications {
id
date
subject
lobbyist_names
government_officials
organization_name
organization_industry
}
}
}
`;
// Bill structure - hierarchical text
export const GET_BILL_STRUCTURE = gql`
query GetBillStructure($number: String!, $session: String!) {
bills(where: { number: $number, session: $session }) {
number
session
title
# Bill versions
versions {
id
version_number
stage
publication_type_name
publication_date
has_amendments
xml_url
pdf_url
}
# Amendment events
amendmentEvents {
id
event_type
description_en
description_fr
event_date
chamber
stage
committee_code
committee_name
report_number
number_of_amendments
}
# Bill parts (top-level divisions)
parts(options: { sort: [{ sequence: ASC }] }) {
id
number
title_en
title_fr
anchor_id
sequence
sections(options: { sort: [{ sequence: ASC }] }) {
id
number
marginal_note_en
marginal_note_fr
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
subsections(options: { sort: [{ sequence: ASC }] }) {
id
number
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
paragraphs(options: { sort: [{ sequence: ASC }] }) {
id
letter
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
subparagraphs(options: { sort: [{ sequence: ASC }] }) {
id
numeral
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
}
}
}
}
}
# Sections not in parts
sections(options: { sort: [{ sequence: ASC }] }) {
id
number
marginal_note_en
marginal_note_fr
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
subsections(options: { sort: [{ sequence: ASC }] }) {
id
number
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
paragraphs(options: { sort: [{ sequence: ASC }] }) {
id
letter
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
subparagraphs(options: { sort: [{ sequence: ASC }] }) {
id
numeral
text_en
text_fr
anchor_id
sequence
# Amendment tracking
has_amendments
text_history_en
current_version
}
}
}
}
}
}
`;
// ============================================
// Dashboard Queries
// ============================================
export const GET_DASHBOARD_STATS = gql`
query GetDashboardStats {
mps(where: { current: true }) {
id
}
bills(options: { limit: 1 }) {
number
}
}
`;
export const GET_TOP_SPENDERS = gql`
query GetTopSpenders($fiscalYear: Int, $limit: Int = 10) {
topSpenders(fiscalYear: $fiscalYear, limit: $limit) {
mp {
...MPBasic
}
total_expenses
}
}
${MP_BASIC_FRAGMENT}
`;
export const GET_INTERJECTION_LEADERBOARD = gql`
query GetInterjectionLeaderboard($party: String, $limit: Int = 100) {
mpInterjectionLeaderboard(party: $party, limit: $limit) {
mp {
...MPBasic
}
interjection_count
}
}
${MP_BASIC_FRAGMENT}
`;
// Optimized dashboard aggregate queries - avoid over-fetching
export const GET_DASHBOARD_COUNTS = gql`
query GetDashboardCounts {
mpsAggregate(where: { current: true }) {
count
}
billsAggregate {
count
}
}
`;
// Server-side randomized MPs with party filtering
export const GET_RANDOM_MPS = gql`
query GetRandomMPs($parties: [String!], $limit: Int = 8) {
randomMPs(parties: $parties, limit: $limit) {
...MPBasic
}
}
${MP_BASIC_FRAGMENT}
`;
export const GET_CONFLICTS_OF_INTEREST = gql`
query GetConflictsOfInterest($limit: Int = 20) {
conflictsOfInterest(limit: $limit) {
mp {
id
name
party
}
organization {
name
industry
}
bill {
number
title
}
suspicion_score
}
}
`;
export const SEARCH_LOBBY_REGISTRATIONS = gql`
query SearchLobbyRegistrations($searchTerm: String, $active: Boolean, $limit: Int) {
searchLobbyRegistrations(searchTerm: $searchTerm, active: $active, limit: $limit) {
id
reg_number
client_org_name
registrant_name
effective_date
active
subject_matters
}
}
`;
export const GET_PARTY_SPENDING_TRENDS = gql`
query GetPartySpendingTrends($fiscalYear: Int) {
partySpendingTrends(fiscalYear: $fiscalYear) {
quarter
period
parties {
party
total_expenses
mp_count
average_per_mp
}
total_all_parties
}
}
`;
// ============================================
// Committee Queries
// ============================================
export const GET_COMMITTEES = gql`
query GetCommittees {
committees {
code
name
mandate
chamber
membersAggregate {
count
}
latestMeetingDate
latestMeetingNumber
totalMeetingsCount
}
}
`;
export const GET_COMMITTEE = gql`
query GetCommittee($code: ID!) {
committees(where: { code: $code }) {
code
name
mandate
chamber
members {
id
name
party
riding
cabinet_position
servedOnConnection(where: { node: { code: $code } }) {
edges {
properties {
role
}
}
}
}
bills {
number
title
status
session
}
meetings(options: { limit: 5, sort: [{ date: DESC }] }) {
date
number
has_evidence
}
}
}
`;
export const GET_COMMITTEE_MEETINGS = gql`
query GetCommitteeMeetings($code: ID!) {
committees(where: { code: $code }) {
meetings(options: { limit: 50, sort: [{ date: DESC }] }) {
id
date
number
in_camera
has_evidence
meeting_url
session
parliament
}
}
}
`;
export const GET_COMMITTEE_TESTIMONY = gql`
query GetCommitteeTestimony($committeeCode: String!, $limit: Int = 20) {
committeeTestimony(committeeCode: $committeeCode, limit: $limit) {
...StatementBasic
madeBy {
id
name
party
}
partOf {
id
date
document_type
session_id
}
}
}
${STATEMENT_FRAGMENT}
`;
export const GET_COMMITTEE_ACTIVITY_METRICS = gql`
query GetCommitteeActivityMetrics($committeeCode: String!) {
committeeActivityMetrics(committeeCode: $committeeCode) {
committee {
code
name
}
total_meetings
meetings_last_30_days
meetings_last_90_days
total_evidence_documents
active_bills_count
member_count
avg_statements_per_meeting
}
}
`;
// ============================================
// Hansard Queries
// ============================================
export const GET_MP_SPEECHES = gql`
query GetMPSpeeches($mpId: ID!, $limit: Int = 20, $documentType: String) {
mpSpeeches(mpId: $mpId, limit: $limit, documentType: $documentType) {
...StatementBasic
madeBy {
id
name
party
}
partOf {
id
date
document_type
session_id
}
}
}
${STATEMENT_FRAGMENT}
`;
export const GET_BILL_DEBATES = gql`
query GetBillDebates($billNumber: String!, $session: String!, $limit: Int = 50, $debateStage: String) {
billDebates(billNumber: $billNumber, session: $session, limit: $limit, debateStage: $debateStage) {
...StatementBasic
madeBy {
id
name
party
}
mentionsConnection {
edges {
properties {
debate_stage
}
}
}
}
}
${STATEMENT_FRAGMENT}
`;
export const SEARCH_HANSARD = gql`
query SearchHansard($query: String!, $limit: Int = 50, $language: String = "en") {
searchHansard(query: $query, limit: $limit, language: $language) {
...StatementBasic
madeBy {
id
name
party
}
partOf {
id
date
document_type
session_id
presentedTo {
code
name
chamber
}
}
}
}
${STATEMENT_FRAGMENT}
`;
export const GET_HANSARD_DOCUMENT = gql`
query GetHansardDocument {
documents(options: { limit: 100, sort: [{ date: DESC }] }) {
id
date
number
session_id
document_type
xml_source_url
statements {
...StatementBasic
madeBy {
id
name
party
}
}
}
}
${STATEMENT_FRAGMENT}
`;
export const GET_RECENT_DEBATES = gql`
query GetRecentDebates(
$limit: Int = 20
$documentType: String
$questionPeriodOnly: Boolean = false
$startDate: String
$endDate: String
) {
recentDebates(
limit: $limit
documentType: $documentType
questionPeriodOnly: $questionPeriodOnly
startDate: $startDate
endDate: $endDate
) {
document {
id
date
session_id
document_type
number
keywords_en
keywords_fr
}
statement_count
speaker_count
top_topics
}
}
`;
export const GET_RECENT_STATEMENTS = gql`
query GetRecentStatements($limit: Int = 10, $offset: Int = 0) {
statements(
options: { limit: $limit, offset: $offset, sort: [{ time: DESC }] }
) {
...StatementBasic
madeBy {
id
name
party
}
partOf {
id
date
document_type
session_id
presentedTo {
code
name
chamber
}
}
}
}
${STATEMENT_FRAGMENT}
`;
// ============================================
// Lobbying Fragments
// ============================================
export const ORGANIZATION_BASIC_FRAGMENT = gql`
fragment OrganizationBasic on Organization {
id
name
industry
}
`;
export const LOBBYIST_BASIC_FRAGMENT = gql`
fragment LobbyistBasic on Lobbyist {
id
name
firm
}
`;
// ============================================
// Lobbying Queries
// ============================================
export const GET_MP_LOBBYING = gql`
query GetMPLobbying($mpId: ID!, $limit: Int = 10, $after: String) {
mps(where: { id: $mpId }) {
id
name
metWithConnection(
first: $limit
after: $after
sort: [{ edge: { last_contact: DESC } }, { edge: { first_contact: DESC } }]
) {
totalCount
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
properties {
first_contact
last_contact
}
node {
...LobbyistBasic
worksFor {
...OrganizationBasic
}
}
}
}
}
}
${LOBBYIST_BASIC_FRAGMENT}
${ORGANIZATION_BASIC_FRAGMENT}
`;
export const GET_LOBBYIST = gql`
query GetLobbyist($id: ID!) {
lobbyists(where: { id: $id }) {
id
name
firm
worksFor {
...OrganizationBasic
}
metWithConnection(
first: 50
sort: [{ edge: { last_contact: DESC } }]
) {
totalCount
edges {
properties {
first_contact
last_contact
}
node {
id
name
party
riding
}
}
}
registeredForConnection {
totalCount
edges {
node {
id
reg_number
active
effective_date
end_date
}
}
}
}
}
${ORGANIZATION_BASIC_FRAGMENT}
`;
export const GET_ORGANIZATION = gql`
query GetOrganization($id: ID!) {
organizations(where: { id: $id }) {
id
name
industry
lobbyistsConnection {
totalCount
edges {
node {
...LobbyistBasic
}
}
}
lobbiedOnConnection(first: 20) {
totalCount
edges {
properties {
date
subject
}
node {
number
session
title
title_fr
status
}
}
}
registrationsConnection(first: 20) {
totalCount
edges {
node {
id
reg_number
registrant_name
active
effective_date
}
}
}
}
}
${LOBBYIST_BASIC_FRAGMENT}
`;
export const GET_DASHBOARD_LOBBYING = gql`
query GetDashboardLobbying {
lobbyCommunications(
options: {
limit: 10
sort: [{ date: DESC }]
}
) {
id
date
client_org_name
registrant_name
dpoh_names
subject_matters
organization {
id
name
}
lobbyist {
id
name
}
}
}
`;
export const SEARCH_ORGANIZATIONS = gql`
query SearchOrganizations($searchTerm: String!, $limit: Int = 20) {
searchOrganizations(searchTerm: $searchTerm, limit: $limit) {
...OrganizationBasic
lobbyistsConnection {
totalCount
}
registrationsConnection(where: { active: true }) {
totalCount
}
}
}
${ORGANIZATION_BASIC_FRAGMENT}
`;
export const SEARCH_LOBBYISTS = gql`
query SearchLobbyists($searchTerm: String!, $limit: Int = 20) {
searchLobbyists(searchTerm: $searchTerm, limit: $limit) {
...LobbyistBasic
worksFor {
...OrganizationBasic
}
metWithConnection {
totalCount
}
}
}
${LOBBYIST_BASIC_FRAGMENT}
${ORGANIZATION_BASIC_FRAGMENT}
`;
// Detailed Lobby Communication Queries
export const GET_MP_LOBBY_COMMUNICATIONS = gql`
query GetMPLobbyCommunications($mpId: ID!, $limit: Int = 10, $offset: Int = 0) {
lobbyCommunications(
where: {
contacted_SOME: {
id: $mpId
}
}
options: {
limit: $limit
offset: $offset
sort: [{ date: DESC }]
}
) {
id
date
dpoh_names
dpoh_titles
subject_matters
institutions
client_org_name
registrant_name
organization {
id
name
industry
}
lobbyist {
id
name
firm
}
}
lobbyCommunicationsAggregate(
where: {
contacted_SOME: {
id: $mpId
}
}
) {
count
}
}
`;
export const GET_LOBBYIST_COMMUNICATIONS = gql`
query GetLobbyistCommunications($lobbyistId: ID!, $limit: Int = 50) {
lobbyCommunications(
where: {
lobbyist: {
id: $lobbyistId
}
}
options: {
limit: $limit
sort: [{ date: DESC }]
}
) {
id
date
dpoh_names
dpoh_titles
subject_matters
institutions
client_org_name
organization {
id
name
industry
}
contacted {
id
name
party
riding
}
}
}
`;
export const GET_ORGANIZATION_COMMUNICATIONS = gql`
query GetOrganizationCommunications($organizationId: ID!, $limit: Int = 50) {
lobbyCommunications(
where: {
organization: {
id: $organizationId
}
}
options: {
limit: $limit
sort: [{ date: DESC }]
}
) {
id
date
dpoh_names
dpoh_titles
subject_matters
institutions
registrant_name
lobbyist {
id
name
firm
}
contacted {
id
name
party
riding
}
}
}
`;
// ============================================
// Debate/Hansard Document Queries
// ============================================
export const GET_QUESTION_PERIOD_DEBATES = gql`
query GetQuestionPeriodDebates($limit: Int = 10, $sinceDate: Date) {
questionPeriodDebates(limit: $limit, sinceDate: $sinceDate) {
document {
id
date
session_id
document_type
number
keywords_en
keywords_fr
}
statement_count
speaker_count
top_topics
is_question_period
}
}
`;
export const GET_DEBATE_WITH_STATEMENTS = gql`
query GetDebateWithStatements($documentId: ID!, $includeThreading: Boolean = true) {
debateWithStatements(documentId: $documentId, includeThreading: $includeThreading) {
document {
id
date
session_id
document_type
number
xml_source_url
}
statements {
id
# time field removed - causes APOC date parsing error
who_en
who_fr
content_en
content_fr
h1_en
h2_en
h3_en
h1_fr
h2_fr
h3_fr
statement_type
politician_id
thread_id
parent_statement_id
sequence_in_thread
wordcount
procedural
madeBy {
id
name
party
photo_url
photo_url_source
}
partOf {
id
date
document_type
}
}
sections
statement_count
}
}
`;
export const GET_DEBATES_CALENDAR_DATA = gql`
query GetDebatesCalendarData($startDate: String!, $endDate: String!) {
debatesCalendarData(startDate: $startDate, endDate: $endDate) {
date
hasHouseDebates
hasQuestionPeriod
hasCommittee
hasScheduledMeeting
scheduledMeetings {
committee_code
committee_name
number
in_camera
}
}
}
`;
// ============================================
// Written Questions Queries
// ============================================
export const GET_WRITTEN_QUESTIONS = gql`
query GetWrittenQuestions($limit: Int, $answered: Boolean, $mpId: ID, $session: String) {
writtenQuestions(limit: $limit, answered: $answered, mpId: $mpId, session: $session) {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
h1_en
h2_en
h3_en
h1_fr
h2_fr
h3_fr
wordcount
answer {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
}
madeBy {
id
name
party
riding
photo_url
photo_url_source
}
partOf {
id
date
document_type
session_id
}
}
}
`;
export const GET_MP_WRITTEN_QUESTIONS = gql`
query GetMPWrittenQuestions($mpId: ID!, $limit: Int, $session: String) {
writtenQuestionsByMP(mpId: $mpId, limit: $limit, session: $session) {
id
question_number
parliament_number
session_number
session_id
date_asked
asker_name
status
due_date
answer_date
question_text
sessional_paper
ourcommons_url
askedBy {
id
name
party
riding
photo_url
}
}
}
`;
export const GET_WRITTEN_QUESTION_SESSIONS = gql`
query GetWrittenQuestionSessions {
writtenQuestionSessions
}
`;
export const GET_MP_ANSWERED_QUESTIONS = gql`
query GetMPAnsweredQuestions($mpId: ID!, $limit: Int, $session: String) {
mpAnsweredQuestions(mpId: $mpId, limit: $limit, session: $session) {
question {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
h1_en
h2_en
h3_en
h1_fr
h2_fr
h3_fr
wordcount
madeBy {
id
name
party
riding
photo_url
}
}
answer {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
}
partOf {
id
date
document_type
session_id
}
}
}
`;
export const SEARCH_WRITTEN_QUESTIONS = gql`
query SearchWrittenQuestions($searchTerm: String!, $limit: Int, $language: String) {
searchWrittenQuestions(searchTerm: $searchTerm, limit: $limit, language: $language) {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
h1_en
h2_en
h3_en
h1_fr
h2_fr
h3_fr
wordcount
answer {
id
# time removed - APOC error
who_en
who_fr
content_en
content_fr
}
madeBy {
id
name
party
riding
photo_url
photo_url_source
}
partOf {
id
date
document_type
}
}
}
`;
// Bill Committee Evidence - Get committee meetings and testimony
// ============================================
// Government Spending Queries
// ============================================
export const SEARCH_FEDERAL_CONTRACTS = gql`
query SearchFederalContracts(
$vendorName: String
$department: String
$year: Int
$minAmount: Float
$maxAmount: Float
$limit: Int = 20
) {
contracts(
where: {
vendor_CONTAINS: $vendorName
department_CONTAINS: $department
year: $year
amount_GTE: $minAmount
amount_LTE: $maxAmount
}
options: { limit: $limit, sort: [{ amount: DESC }] }
) {
id
vendor
amount
department
date
description
year
}
}
`;
export const GET_TOP_CONTRACTORS = gql`
query GetTopContractors($department: String, $year: Int, $limit: Int = 10) {
topContractors(department: $department, year: $year, limit: $limit) {
vendor
total_amount
contract_count
}
}
`;
export const SEARCH_POLITICAL_CONTRIBUTIONS = gql`
query SearchPoliticalContributions(
$donorName: String
$party: String
$year: Int
$minAmount: Float
$maxAmount: Float
$province: String
$limit: Int = 20
) {
donations(
where: {
donor_name_CONTAINS: $donorName
contribution_year: $year
amount_GTE: $minAmount
amount_LTE: $maxAmount
province: $province
}
options: { limit: $limit, sort: [{ amount: DESC }] }
) {
id
donor_name
amount
date
contribution_year
province
receivedBy {
code
name
}
}
}
`;
export const GET_TOP_POLITICAL_DONORS = gql`
query GetTopPoliticalDonors($party: String, $year: Int, $limit: Int = 10) {
topPoliticalDonors(party: $party, year: $year, limit: $limit) {
donor_name
total_amount
donation_count
parties
}
}
`;
export const GET_PARTY_FUNDRAISING = gql`
query GetPartyFundraising($year: Int) {
partyFundraising(year: $year) {
party
year
total_amount
donation_count
unique_donors
average_donation
}
}
`;
export const SEARCH_FEDERAL_GRANTS = gql`
query SearchFederalGrants(
$recipientName: String
$programName: String
$department: String
$province: String
$year: Int
$minAmount: Float
$maxAmount: Float
$limit: Int = 20
) {
grants(
where: {
recipient_CONTAINS: $recipientName
program_name_CONTAINS: $programName
department_CONTAINS: $department
province: $province
year: $year
amount_GTE: $minAmount
amount_LTE: $maxAmount
}
options: { limit: $limit, sort: [{ amount: DESC }] }
) {
id
recipient
amount
program_name
program_purpose
department
date
year
province
}
}
`;
export const GET_TOP_GRANT_RECIPIENTS = gql`
query GetTopGrantRecipients($program: String, $year: Int, $limit: Int = 20) {
topGrantRecipients(program: $program, year: $year, limit: $limit) {
recipient
recipient_city
recipient_province
total_amount
grant_count
programs
}
}
`;
export const GET_GRANT_PROGRAM_SPENDING = gql`
query GetGrantProgramSpending($year: Int, $limit: Int = 50) {
grantProgramSpending(year: $year, limit: $limit) {
program_name
program_purpose
department
total_amount
grant_count
unique_recipients
}
}
`;
export const TRACE_MONEY_FLOW = gql`
query TraceMoneyFlow($entityName: String!, $year: Int, $includeContracts: Boolean = true, $includeGrants: Boolean = true, $includeContributions: Boolean = true, $includeLobbying: Boolean = true) {
traceMoneyFlow(entityName: $entityName, year: $year, includeContracts: $includeContracts, includeGrants: $includeGrants, includeContributions: $includeContributions, includeLobbying: $includeLobbying) {
entity_name
contracts {
total_amount
count
departments
}
grants {
total_amount
count
programs
}
donations {
total_amount
count
parties
}
lobbying {
registration_count
communication_count
subjects
}
}
}
`;
export const ANALYZE_MP_FINANCES = gql`
query AnalyzeMPFinances($mpId: ID!, $fiscalYear: Int, $includeLobbying: Boolean = true) {
analyzeMPFinances(mpId: $mpId, fiscalYear: $fiscalYear, includeLobbying: $includeLobbying) {
mp {
id
name
party
riding
}
expenses {
total
by_category {
category
amount
}
fiscal_year
}
lobbying_contacts {
count
organizations
}
}
}
`;
export const COMPARE_PARTY_FUNDING = gql`
query ComparePartyFunding($year: Int, $includeDonorAnalysis: Boolean = true, $minDonation: Float = 0) {
comparePartyFunding(year: $year, includeDonorAnalysis: $includeDonorAnalysis, minDonation: $minDonation) {
parties {
party
total_raised
donor_count
average_donation
top_donors
}
year
}
}
`;
export const GOVERNMENT_SPENDING_ANALYSIS = gql`
query GovernmentSpendingAnalysis($departmentName: String, $year: Int, $focus: String = "all", $limit: Int = 10) {
governmentSpendingAnalysis(departmentName: $departmentName, year: $year, focus: $focus, limit: $limit) {
department
contracts {
total_amount
count
top_vendors
}
grants {
total_amount
count
top_programs
}
}
}
`;
export const ANALYZE_INDUSTRY_INFLUENCE = gql`
query AnalyzeIndustryInfluence($industryKeyword: String!, $limit: Int = 10) {
analyzeIndustryInfluence(industryKeyword: $industryKeyword, limit: $limit) {
industry
active_organizations {
organization
registration_count
}
total_registrations
communication_count
top_contacted_officials
targeted_institutions {
institution
count
}
}
}
`;
export const CONFLICT_OF_INTEREST_CHECK = gql`
query ConflictOfInterestCheck($entityName: String!, $year: Int, $thresholdAmount: Float = 100000) {
conflictOfInterestCheck(entityName: $entityName, year: $year, thresholdAmount: $thresholdAmount) {
entity_name
contributions {
total
count
parties
}
contracts {
count
items {
amount
department
date
}
}
grants {
count
items {
amount
program
date
}
}
lobbying {
registration_count
subjects
}
potential_concerns
has_concerns
}
}
`;
// ============================================
// Petitions Queries
// ============================================
export const SEARCH_PETITIONS = gql`
query SearchPetitions($keyword: String, $sponsorName: String, $category: String, $status: String, $limit: Int = 20) {
petitions(
where: {
OR: [
{ title_CONTAINS: $keyword }
{ text_CONTAINS: $keyword }
]
status: $status
}
options: { limit: $limit, sort: [{ signatures: DESC }] }
) {
number
title
text
signatures
status
sponsor {
id
name
party
}
}
}
`;
export const GET_PETITION_DETAILS = gql`
query GetPetitionDetails($petitionNumber: String!) {
petitions(where: { number: $petitionNumber }) {
number
title
text
signatures
status
sponsor {
id
name
party
riding
}
}
}
`;
export const GET_MP_PETITIONS = gql`
query GetMPPetitions($mpId: ID!, $limit: Int = 20) {
mps(where: { id: $mpId }) {
id
name
sponsoredPetitions(options: { limit: $limit, sort: [{ signatures: DESC }] }) {
number
title
text
signatures
status
}
}
}
`;
// ============================================
// Advanced MP Analysis Queries
// ============================================
export const GET_MP_VOTING_HISTORY = gql`
query GetMPVotingHistory($mpId: ID!, $limit: Int = 50) {
mps(where: { id: $mpId }) {
id
name
party
votedConnection(first: $limit, sort: [{ node: { date: DESC } }]) {
edges {
properties {
position
}
node {
id
number
date
result
yeas
nays
description
bill_number
subjectOf {
number
title
session
}
}
}
}
}
}
`;
export const GET_VOTE_DETAILS = gql`
query GetVoteDetails($voteId: ID!, $includeBallots: Boolean = true) {
votes(where: { id: $voteId }) {
id
number
date
result
yeas
nays
paired
description
bill_number
subjectOf {
number
title
session
status
}
ballots @include(if: $includeBallots) {
id
vote_value
is_yea
is_nay
castBy {
id
name
party
riding
}
}
}
}
`;
export const ANALYZE_PARTY_DISCIPLINE = gql`
query AnalyzePartyDiscipline($party: String) {
partyDisciplineAnalysis(party: $party) {
mp_id
mp_name
party
total_votes
aligned_votes
discipline_rate
}
}
`;
export const COMPARE_MP_PERFORMANCE = gql`
query CompareMPPerformance($mpIds: [ID!]!) {
compareMPPerformance(mpIds: $mpIds) {
mp_id
mp_name
party
riding
bills_sponsored
bills_passed
votes_participated
committee_memberships
total_statements
}
}
`;
export const TRACK_COMMITTEE_ACTIVITY = gql`
query TrackCommitteeActivity($mpId: ID!) {
mpCommitteeActivity(mpId: $mpId) {
mp_id
mp_name
committees {
code
name
role
start_date
}
total_committees
evidence_statements
}
}
`;
export const ANALYZE_MP_VOTING_PARTICIPATION = gql`
query AnalyzeMPVotingParticipation($mpId: ID!) {
mpVotingParticipation(mpId: $mpId) {
mp_id
mp_name
party
votes_participated
total_votes
participation_rate
yea_votes
nay_votes
paired_votes
}
}
`;
// ============================================
// Bill Analysis Queries
// ============================================
export const COMPARE_PARTY_BILLS = gql`
query ComparePartyBills {
partyBillsComparison {
party
total_bills
passed_bills
in_committee
second_reading
}
}
`;
export const GET_BILL_LEGISLATIVE_PROGRESS = gql`
query GetBillLegislativeProgress($billNumber: String!, $session: String!) {
bills(where: { number: $billNumber, session: $session }) {
number
session
title
status
stage
introduced_date
passed_house_first_reading
passed_house_second_reading
passed_house_third_reading
passed_senate_first_reading
passed_senate_second_reading
passed_senate_third_reading
royal_assent
latest_event
referredTo {
code
name
}
votes(options: { sort: [{ date: ASC }] }) {
id
date
result
description
}
}
}
`;
export const ANALYZE_MP_BILLS = gql`
query AnalyzeMPBills($mpId: ID!) {
mps(where: { id: $mpId }) {
id
name
party
sponsored(options: { sort: [{ introduced_date: DESC }] }) {
number
session
title
status
stage
introduced_date
is_government_bill
is_private_member_bill
bill_type
}
}
}
`;
// ============================================
// Extended Lobbying Queries
// ============================================
export const SEARCH_LOBBYING_COMMUNICATIONS = gql`
query SearchLobbyCommunications(
$clientName: String
$lobbyistName: String
$subjectKeyword: String
$institution: String
$dateFrom: String
$dateTo: String
$limit: Int = 20
) {
lobbyCommunications(
where: {
client_org_name_CONTAINS: $clientName
subject_matters_INCLUDES: $subjectKeyword
}
options: { limit: $limit, sort: [{ date: DESC }] }
) {
id
date
client_org_name
registrant_name
dpoh_names
dpoh_titles
subject_matters
institutions
organization {
id
name
industry
}
lobbyist {
id
name
firm
}
}
}
`;
export const GET_TOP_LOBBYING_CLIENTS = gql`
query GetTopLobbyingClients($limit: Int = 20) {
topLobbyingClients(limit: $limit) {
client_name
communication_count
top_subjects
}
}
`;
// ============================================
// Cross-Source Search Queries
// ============================================
export const SEARCH_TOPIC_ACROSS_SOURCES = gql`
query SearchTopicAcrossSources($searchTerm: String!, $sources: [String!], $limit: Int = 20) {
searchAcrossSources(searchTerm: $searchTerm, sources: $sources, limit: $limit) {
total_count
results {
id
name
source_type
extra
}
}
}
`;
// ============================================
// GC InfoBase Queries (Departmental Performance & Spending)
// ============================================
export const GET_DEPARTMENT_SPENDING = gql`
query GetDepartmentSpending($department: String!, $fiscalYear: String, $program: String) {
getDepartmentSpending(department: $department, fiscalYear: $fiscalYear, program: $program) {
organization
fiscal_year
program
planned_spending
actual_spending
variance
fte_planned
fte_actual
}
}
`;
export const GET_DEPARTMENT_RESULTS = gql`
query GetDepartmentResults($department: String!, $fiscalYear: String, $program: String) {
getDepartmentResults(department: $department, fiscalYear: $fiscalYear, program: $program) {
organization
fiscal_year
program
indicator_name
target
actual_result
met_target
}
}
`;
export const COMPARE_PLAN_VS_ACTUAL = gql`
query ComparePlanVsActual($department: String!, $fiscalYear: String!) {
comparePlanVsActual(department: $department, fiscalYear: $fiscalYear) {
department
fiscal_year
spending {
planned
actual
variance
variance_percent
}
fte {
planned
actual
variance
}
performance {
targets_met
targets_missed
targets_unknown
success_rate
}
program_count
}
}
`;
export const GET_TOP_SPENDING_DEPARTMENTS = gql`
query GetTopSpendingDepartments($fiscalYear: String, $limit: Int = 20) {
getTopSpendingDepartments(fiscalYear: $fiscalYear, limit: $limit) {
organization
fiscal_year
total_spending
total_fte
program_count
}
}
`;
export const SEARCH_GC_INFOBASE = gql`
query SearchGCInfoBase($query: String!, $fiscalYear: String, $limit: Int = 50) {
searchGCInfoBase(query: $query, fiscalYear: $fiscalYear, limit: $limit) {
total_count
results {
type
organization
program
fiscal_year
actual_spending
indicator
}
}
}
`;
// ============================================
// ATIP Request Queries (Access to Information)
// ============================================
export const SEARCH_ATIP_REQUESTS = gql`
query SearchATIPRequests(
$query: String
$organization: String
$year: Int
$disposition: String
$limit: Int = 50
) {
searchATIPRequests(
query: $query
organization: $organization
year: $year
disposition: $disposition
limit: $limit
) {
id
request_number
year
month
date
organization
organization_code
summary_en
summary_fr
disposition
disposition_description
pages
}
}
`;
export const GET_ATIP_STATS_BY_ORGANIZATION = gql`
query GetATIPStatsByOrganization(
$organization: String
$year: Int
$limit: Int = 20
) {
getATIPStatsByOrganization(
organization: $organization
year: $year
limit: $limit
) {
organization
organization_code
total_requests
total_pages
disclosed_all
disclosed_part
no_records
}
}
`;
export const GET_ATIP_TRENDS = gql`
query GetATIPTrends($organization: String, $years: Int = 5) {
getATIPTrends(organization: $organization, years: $years) {
organization
by_year {
year
requests
pages
}
by_disposition {
disposition
count
}
total_requests
total_pages
}
}
`;
// ============================================
// Government Consultations Queries
// ============================================
export const SEARCH_CONSULTATIONS = gql`
query SearchConsultations(
$query: String
$organization: String
$subject: String
$status: String
$year: Int
$limit: Int = 50
) {
searchConsultations(
query: $query
organization: $organization
subject: $subject
status: $status
year: $year
limit: $limit
) {
id
registration_number
title_en
title_fr
description_en
description_fr
start_date
end_date
start_year
status
status_description
subjects
subject_descriptions
organization
organization_code
partner_departments
profile_page_en
profile_page_fr
report_available_online
report_link_en
report_link_fr
}
}
`;
export const GET_OPEN_CONSULTATIONS = gql`
query GetOpenConsultations(
$organization: String
$subject: String
$limit: Int = 50
) {
getOpenConsultations(
organization: $organization
subject: $subject
limit: $limit
) {
id
registration_number
title_en
description_en
start_date
end_date
status_description
subjects
subject_descriptions
organization
profile_page_en
}
}
`;
export const GET_CONSULTATION_STATS_BY_ORGANIZATION = gql`
query GetConsultationStatsByOrganization(
$organization: String
$year: Int
$limit: Int = 20
) {
getConsultationStatsByOrganization(
organization: $organization
year: $year
limit: $limit
) {
organization
organization_code
total_consultations
open_count
completed_count
with_reports
}
}
`;
export const GET_CONSULTATION_STATS_BY_SUBJECT = gql`
query GetConsultationStatsBySubject($year: Int, $limit: Int = 20) {
getConsultationStatsBySubject(year: $year, limit: $limit) {
subject_code
total_consultations
open_count
completed_count
}
}
`;
// ============================================
// Departmental Travel & Hospitality Queries
// ============================================
export const SEARCH_DEPARTMENTAL_TRAVEL = gql`
query SearchDepartmentalTravel(
$department: String
$name: String
$destination: String
$year: Int
$minAmount: Float
$disclosureGroup: String
$limit: Int = 50
) {
searchDepartmentalTravel(
department: $department
name: $name
destination: $destination
year: $year
minAmount: $minAmount
disclosureGroup: $disclosureGroup
limit: $limit
) {
id
ref_number
organization
organization_code
disclosure_group
title_en
name
purpose_en
start_date
end_date
travel_year
destination_en
airfare
other_transport
lodging
meals
other_expenses
total
}
}
`;
export const SEARCH_DEPARTMENTAL_HOSPITALITY = gql`
query SearchDepartmentalHospitality(
$department: String
$name: String
$location: String
$year: Int
$minAmount: Float
$disclosureGroup: String
$limit: Int = 50
) {
searchDepartmentalHospitality(
department: $department
name: $name
location: $location
year: $year
minAmount: $minAmount
disclosureGroup: $disclosureGroup
limit: $limit
) {
id
ref_number
organization
organization_code
disclosure_group
title_en
name
purpose_en
start_date
end_date
hospitality_year
attendees
location_en
total
}
}
`;
export const GET_TOP_TRAVELERS = gql`
query GetTopTravelers($department: String, $year: Int, $limit: Int = 20) {
getTopTravelers(department: $department, year: $year, limit: $limit) {
name
organization
total_spending
trip_count
}
}
`;
export const GET_DEPARTMENT_TRAVEL_SPENDING = gql`
query GetDepartmentTravelSpending($year: Int, $limit: Int = 20) {
getDepartmentTravelSpending(year: $year, limit: $limit) {
organization
organization_code
total_spending
record_count
airfare_total
lodging_total
meals_total
}
}
`;
export const GET_DEPARTMENT_HOSPITALITY_SPENDING = gql`
query GetDepartmentHospitalitySpending($year: Int, $limit: Int = 20) {
getDepartmentHospitalitySpending(year: $year, limit: $limit) {
organization
organization_code
total_spending
record_count
total_attendees
}
}
`;
export const GET_BILL_COMMITTEE_EVIDENCE = gql`
query GetBillCommitteeEvidence($billNumber: String!, $session: String!) {
bills(where: { number: $billNumber, session: $session }) {
number
session
# Committees that this bill was referred to
referredTo {
code
name
# Meetings held by this committee (filter for relevance to the bill in component)
meetings(options: { sort: [{ date: DESC }], limit: 50 }) {
id
ourcommons_meeting_id
date
subject
number
status
webcast
# Evidence from this meeting
evidence {
id
committee_code
meeting_number
date
publication_status
source_xml_url
# All testimonies from this evidence (filter for bill mentions in component)
testimonies(options: { limit: 100 }) {
id
speaker_name
organization
role
text
is_witness
timestamp_hour
timestamp_minute
# Link to MP if the speaker is an MP
speaker {
id
name
party
riding
photo_url
photo_url_source
}
}
}
}
}
}
}
`;
// ============================================
// Fact-Check Queries
// ============================================
export const GET_FACT_CHECK_BY_HASH = gql`
query GetFactCheckByClaimHash($claimHash: String!) {
getFactCheckByClaimHash(claimHash: $claimHash) {
id
claim_text
claim_text_hash
verdict
confidence
rationale
rationale_short
citations
model_used
processing_time_ms
verification_mode
checked_at
created_at
source_statement_id
}
}
`;
export const GET_FACT_CHECKS_FOR_STATEMENT = gql`
query GetFactChecksForStatement($statementId: ID!) {
getFactChecksForStatement(statementId: $statementId) {
id
claim_text
claim_text_hash
verdict
confidence
rationale
rationale_short
citations
model_used
processing_time_ms
verification_mode
checked_at
created_at
source_statement_id
}
}
`;
export const GET_RECENT_FACT_CHECKS = gql`
query GetRecentFactChecks($limit: Int = 10) {
recentFactChecks(limit: $limit) {
id
claim_text
claim_text_hash
verdict
confidence
rationale
rationale_short
citations
model_used
processing_time_ms
verification_mode
checked_at
created_at
source_statement_id
}
}
`;
// ============================================
// Visualizer Queries
// ============================================
export const GET_SEATS_BY_PROVINCE_AND_PARTY = gql`
query GetSeatsByProvinceAndParty {
seatsByProvinceAndParty {
province
party
seats
}
}
`;
export const GET_NATIONAL_SEAT_TOTALS = gql`
query GetNationalSeatTotals {
nationalSeatTotals {
party
seats
}
}
`;