~sircmpwn/meta.sr.ht

df32fd24bfaa0b02d15cbdfbfe95e1b2c19daf8d — Drew DeVault 2 months ago d8899ee 0.44.0
Rig up new core.sr.ht GraphQL interface
5 files changed, 48 insertions(+), 82 deletions(-)

M metasrht/app.py
A metasrht/default_query.graphql
A metasrht/schema.graphqls
D metasrht/templates/graphql.html
M setup.py
M metasrht/app.py => metasrht/app.py +2 -0
@@ 25,6 25,7 @@ class MetaApp(SrhtFlask):
        from metasrht.blueprints.profile import profile
        from metasrht.blueprints.security import security
        from metasrht.blueprints.users import users
        from srht.graphql import gql_blueprint

        self.register_blueprint(auth)
        self.register_blueprint(invites)


@@ 36,6 37,7 @@ class MetaApp(SrhtFlask):
        self.register_blueprint(security)
        self.register_blueprint(users)
        register_api(self)
        self.register_blueprint(gql_blueprint)

        if cfg("meta.sr.ht::billing", "enabled") == "yes":
            from metasrht.blueprints.billing import billing

A metasrht/default_query.graphql => metasrht/default_query.graphql +43 -0
@@ 0,0 1,43 @@
# 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 sshKeys(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
}

A metasrht/schema.graphqls => metasrht/schema.graphqls +1 -0
@@ 0,0 1,1 @@
../api/graph/schema.graphqls
\ No newline at end of file

D metasrht/templates/graphql.html => metasrht/templates/graphql.html +0 -82
@@ 1,82 0,0 @@
<!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>

M setup.py => setup.py +2 -0
@@ 52,6 52,8 @@ setup(
          'static/*',
          'static/icons/*',
          'emails/*'
          'schema.graphqls',
          'default_query.graphql',
      ]
  },
  scripts = [