~sircmpwn/meta.sr.ht

f4b79c82b5cc1dcb71951c5da021ad5808ccc1f0 — Drew DeVault 2 months ago f651617 0.43.1
Add custom GraphQL playground template
1 files changed, 82 insertions(+), 0 deletions(-)

A metasrht/templates/graphql.html
A metasrht/templates/graphql.html => metasrht/templates/graphql.html +82 -0
@@ 0,0 1,82 @@
<!DOCTYPE html>
<html>
<head>
  <meta charset=utf-8/>
  <meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">
  <link rel="stylesheet" href="/static/graphql.css">
  <script src="/static/graphql.js"></script>
  <title>GraphQL API Explorer</title>
</head>
<body>
<style type="text/css">
  html { font-family: "Open Sans", sans-serif; overflow: hidden; }
  body { margin: 0; background: #172a3a; }
  noscript { display: block; text-align: center; color: white; }
</style>
<noscript>
  Sorry, this tool requires JavaScript to be enabled.
</noscript>
<div id="root"/>
<script type="text/javascript">
  window.addEventListener('load', function (event) {
    const root = document.getElementById('root');
    root.classList.add('playgroundIn');
    const wsProto = location.protocol == 'https:' ? 'wss:' : 'ws:'
    GraphQLPlayground.init(root, {
      endpoint: location.protocol + '//' + location.host + '/query',
      settings: {
        'request.credentials': 'same-origin'
      },
      tabs: [
        {
          name: "List SSH keys",
          endpoint: location.protocol + '//' + location.host + '/query',
          query: `# Welcome to the SourceHut GraphQL explorer
# You can use this to run test requests against the GraphQL API
# To browse the GraphQL schema, use the "Schema" button on the far right.
# There's a sample query for you here; and more samples in other tabs.
query {
  # Fetch info about the authenticated user (you):
  me {
    # Grab their canonical name:
    canonicalName
    # And a list of their SSH keys:
    sshKeys {
      # This resource is paginated, so it has a cursor. If you pass this value
      # into repositories(cursor:"...") in a subsequent request, you'll get the
      # next page.
      cursor
      # These are the actual results.
      results {
        id
        fingerprint
        comment
      }
    }
  }

  # Also fetch the API version. Please note that the GraphQL API is considered
  # experimental: as long as this returns 0.0.0, the API is subject to change
  # without notice. Some features may not be working; notably, all write
  # operations are presently unsupported.
  version {
    major, minor, patch
  }

  # On this page, you have been automatically authorized to make API requests
  # with your sr.ht login cookie. If you wish to make GraphQL requests outside
  # of the browser, create a personal access token at https://meta.sr.ht/oauth
  #
  # curl \\
  #     -H Authorization:"Bearer <your oauth token>" \\
  #     -H Content-Type:application/json \\
  #     -d '{"query": "{ me { canonicalName } }"}' \\
  #     https://meta.sr.ht/query
}`,
        }
      ]
    })
  })
</script>
</body>
</html>