Skip to content

Commit

Permalink
Fix for the cache + graphql error
Browse files Browse the repository at this point in the history
This fixes the problem we started seeing recently when running `npm run
start` more than once caused a Missing field GraphQL error, which
resulted in the site failing to run and the GraphQL editor to show that
the wikipedia.json file was no longer queryable. Running `npm run clean`
would then allow things to work again. But this caused problems in
environments when we wanted to keep the cache around for a faster build,
and it was just annoying when developing the site.

I tried a bunch of things but ran across an issue on GitHub where
someone said that changing the name of a property from `identifier` to
`name` in the JSON data they were querying made this problem go away. I
didn't have an `identifier` property but I did have an `id` and thought
changing it to `personId` might help. It did make the problem go away. I
tried to document this on GitHub for Gatsby here:

gatsbyjs/gatsby#11747 (comment)

This was a difficult problem to debug, and the solution was really
unsatisfying because I don't understand why it helped. I think if we are
going to continue using Gatsby in the future we might want to invest
some time learning how to define our schema rather than letting Gatsby
infer it.
  • Loading branch information
edsu committed Jul 10, 2021
1 parent 4734d56 commit 37e30cb
Show file tree
Hide file tree
Showing 3 changed files with 582 additions and 582 deletions.
2 changes: 1 addition & 1 deletion src/commands/fetch-wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function scrapeWikipedia(people) {
}

const w = {
id: person.id,
personId: person.id,
url: person.wikidata.wikipediaUrl,
image: null,
imageUrl: null,
Expand Down
18 changes: 9 additions & 9 deletions src/templates/cpf.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,6 @@ const CPF = ({ data }) => {

export const query = graphql`
query($id: String!) {
wikipediaJson(id: {eq: $id}) {
id
abstract
image {
childImageSharp {
gatsbyImageData(width: 300)
}
}
}
peopleJson(id: {eq: $id}) {
id
name
Expand Down Expand Up @@ -257,6 +248,15 @@ export const query = graphql`
wikipediaUrl
}
}
wikipediaJson(personId: {eq: $id}) {
personId
abstract
image {
childImageSharp {
gatsbyImageData(width: 300)
}
}
}
asDocumentCreator: allDocumentsJson(
filter: {creator: {elemMatch: {id: {eq: $id}}}}
) {
Expand Down
Loading

0 comments on commit 37e30cb

Please sign in to comment.