-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Demo fixes #136
Demo fixes #136
Changes from all commits
2b274f9
f0f4d04
08596b2
d1ecb24
081f795
f895502
53a027a
4be79b7
49e6c43
553811e
cf8c74f
14cd302
01c0b7f
2214561
3b9f6ce
cc03d98
64c3c80
9c265a3
3a50923
4158c72
6d5ae70
e53768f
5c88f1d
bbd5892
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const CANDIDATE_NODE_TYPE = `Candidate` | |
const ELECTION_NODE_TYPE = `Election` | ||
const METADATA_NODE_TYPE = `Metadata` | ||
const OFFICE_ELECTION_NODE_TYPE = `OfficeElection` | ||
const REFERENDUM_NODE_TYPE = `Referendum` | ||
|
||
const DUMMY_DATA = { | ||
candidates: { | ||
|
@@ -93,6 +94,8 @@ async function fetchEndpoint(endpoint) { | |
`http://${HOSTNAME}/open-disclosure/api/v1.0/${endpoint}` | ||
) | ||
if (response.ok) { | ||
// NOTE: If `gatsby develop` gives errors related to errors like `Cannot query field "fields" on type "OfficeElection"`, comment return DUMMY_DATA[endpoints] back in | ||
// return DUMMY_DATA[endpoint] | ||
return await response.json() | ||
} | ||
} catch (networkError) { | ||
|
@@ -153,6 +156,22 @@ exports.sourceNodes = async ({ | |
}) | ||
return id | ||
}), | ||
Referendums: election.Referendums.map(referendum => { | ||
const id = createNodeId(`${REFERENDUM_NODE_TYPE}-${election.Date}`) | ||
|
||
createNode({ | ||
...referendum, | ||
id, | ||
parent: null, | ||
children: [], | ||
internal: { | ||
type: REFERENDUM_NODE_TYPE, | ||
content: JSON.stringify(referendum), | ||
contentDigest: createContentDigest(referendum), | ||
}, | ||
}) | ||
return id | ||
}), | ||
id: createNodeId(`${ELECTION_NODE_TYPE}-${election.Date}`), | ||
parent: null, | ||
children: [], | ||
|
@@ -199,17 +218,13 @@ exports.createPages = async ({ graphql, actions }) => { | |
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
allMeasuresJson { | ||
edges { | ||
node { | ||
id | ||
electionDate | ||
name | ||
fields { | ||
slug | ||
Referendums { | ||
Title | ||
Description | ||
TotalContributions | ||
fields { | ||
slug | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -236,15 +251,15 @@ exports.createPages = async ({ graphql, actions }) => { | |
}) | ||
}) | ||
}) | ||
}) | ||
result.data.allMeasuresJson.edges.forEach(({ node }) => { | ||
createPage({ | ||
path: `/${node.electionDate}/referendum/${node.fields.slug}`, | ||
component: path.resolve("src/templates/measure.js"), | ||
context: { | ||
id: node.id, | ||
slug: node.fields.slug, | ||
}, | ||
node.Referendums.forEach(referendum => { | ||
createPage({ | ||
path: `/${node.Date}/referendums/${referendum.fields.slug}`, | ||
component: path.resolve("src/templates/referendum.js"), | ||
context: { | ||
slug: referendum.fields.slug, | ||
id: referendum.ID, | ||
}, | ||
}) | ||
}) | ||
}) | ||
} | ||
|
@@ -275,18 +290,12 @@ exports.createSchemaCustomization = ({ actions }) => { | |
apiNode: Candidate @link(by: "ID" from: "id") | ||
} | ||
|
||
type MeasuresJson implements Node { | ||
electionDate: String! | ||
title: String! | ||
description: String! | ||
ballotLanguage: String! | ||
} | ||
|
||
type Election implements Node { | ||
Title: String! | ||
Date: String | ||
TotalContributions: String | ||
OfficeElections: [OfficeElection] @link | ||
Referendums: [Referendum] @link | ||
} | ||
|
||
type OfficeElection implements Node { | ||
|
@@ -295,6 +304,19 @@ exports.createSchemaCustomization = ({ actions }) => { | |
TotalContributions: String | ||
} | ||
|
||
type Referendum implements Node { | ||
Title: String! | ||
Description: String | ||
Total_Contributions: String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this what the API returns? Can we ask to remove the underscore for consistency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the API returns a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah sounds like we should get rid of the space on the backend if we can |
||
} | ||
|
||
type MeasuresJson implements Node { | ||
electionDate: String! | ||
title: String! | ||
description: String! | ||
ballotLanguage: String! | ||
} | ||
|
||
type Metadata implements Node{ | ||
DateProcessed: String! | ||
} | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to delete the JSON files entirely? That's fine if we're going to get all the data we need from the API, but I was under the impression we'd need to have some client-side data for the measure description, etc. If we no longer need that, let's also delete the json files under /src/data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize that was for the JSON; I'll put it back in.