simonw / datasette.io

The official project website for Datasette
https://datasette.io
92 stars 21 forks source link

Deploys are broken due to GitHub GraphQL endpoint #120

Closed simonw closed 2 years ago

simonw commented 2 years ago

https://github.com/simonw/datasette.io/actions/runs/3156426439/jobs/5136126305

  File "build_directory.py", line 87, in fetch_plugins
    data = client.execute(
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/python_graphql_client/graphql_client.py", line 54, in execute
    result.raise_for_status()
  File "/opt/hostedtoolcache/Python/3.8.14/x64/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 502 Server Error: Bad Gateway for url: https://api.github.com/graphql

Looks like this first broke 3 days ago: https://github.com/simonw/datasette.io/actions/runs/3140951006/jobs/5102874022

simonw commented 2 years ago

Annoyingly it didn't give me that error in local dev:

% export GITHUB_TOKEN=...
% python build_directory.py content.db --fetch-missing-releases \
   --always-fetch-releases-for-repo simonw/datasette-app
Fetching README for ['dogsheep/github-to-sqlite', 'dogsheep/pocket-to-sqlite', 'hydrosquall/datasette-nteract-data-explorer', 'rclement/datasette-dashboards', 'simonw/datasette-app', 'simonw/datasette-block-robots', 'simonw/datasette-edit-schema', 'simonw/datasette-leaflet-geojson', 'simonw/datasette-mp3-audio', 'simonw/datasette-pretty-json', 'simonw/datasette-publish-fly', 'simonw/datasette-publish-vercel', 'simonw/datasette-render-images', 'simonw/datasette-scale-to-zero', 'simonw/datasette-sentry', 'simonw/datasette-upload-csvs', 'simonw/datasette-upload-dbs', 'simonw/git-history', 'simonw/s3-credentials', 'simonw/s3-ocr', 'simonw/shot-scraper', 'simonw/sqlite-diffable', 'simonw/sqlite-utils']
simonw commented 2 years ago

Here's the query it's running. It's pretty big! 4,000 lines now: https://gist.github.com/simonw/80ef5a69f147741009d0edea4ef3b6ea

Truncated version:

{
  repo_0: repository(name: "datasette-query-history", owner: "bretwalker") {
    id
    nameWithOwner
    createdAt
    openGraphImageUrl
    usesCustomOpenGraphImage
    defaultBranchRef {
      target {
        oid
      }
    }
    repositoryTopics(first: 100) {
      totalCount
      nodes {
        topic {
          name
        }
      }
    }
    openIssueCount: issues(states: [OPEN]) {
      totalCount
    }
    closedIssueCount: issues(states: [CLOSED]) {
      totalCount
    }
    releases(last: 1) {
      totalCount
      nodes {
        tagName
      }
    }
  }
  # ...
  repo_137: repository(name: "yaml-to-sqlite", owner: "simonw") {
    id
    nameWithOwner
    createdAt
    openGraphImageUrl
    usesCustomOpenGraphImage
    defaultBranchRef {
      target {
        oid
      }
    }
    repositoryTopics(first: 100) {
      totalCount
      nodes {
        topic {
          name
        }
      }
    }
    openIssueCount: issues(states: [OPEN]) {
      totalCount
    }
    closedIssueCount: issues(states: [CLOSED]) {
      totalCount
    }
    releases(last: 1) {
      totalCount
      nodes {
        tagName
      }
    }
  }
}
simonw commented 2 years ago

I tried running the full ./scripts/build.sh script locally (after setting that GITHUB_TOKEN environment variable) and that worked on my laptop too.

Likewise, the giant GraphQL query worked on https://docs.github.com/en/graphql/overview/explorer

simonw commented 2 years ago

Maybe I can shrink the query using GraphQL fragments: https://www.apollographql.com/docs/react/data/fragments/

simonw commented 2 years ago

Yes this seems to work on https://docs.github.com/en/graphql/overview/explorer

fragment repoFields on Repository {
  id
  nameWithOwner
  createdAt
  openGraphImageUrl
  usesCustomOpenGraphImage
  defaultBranchRef {
    target {
      oid
    }
  }
  repositoryTopics(first: 100) {
    totalCount
    nodes {
      topic {
        name
      }
    }
  }
  openIssueCount: issues(states: [OPEN]) {
    totalCount
  }
  closedIssueCount: issues(states: [CLOSED]) {
    totalCount
  }
  releases(last: 1) {
    totalCount
    nodes {
      tagName
    }
  }
}
{
  repo_0: repository(name: "datasette-query-history", owner: "bretwalker") {
    ...repoFields
  }
  repo_1: repository(name: "datasette-graphql", owner: "simonw") {
    ...repoFields
  }
}
simonw commented 2 years ago

That seems to have fixed it. Or at least deploys are working again now.