From fe63de605c41afd909c547cafe0412eaca07312d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 28 May 2020 15:39:03 -0400 Subject: [PATCH] API: update GraphQL explorer page --- gitsrht/app.py | 2 ++ gitsrht/default_query.graphql | 41 +++++++++++++++++++++++++++++++++++ gitsrht/schema.graphqls | 1 + 3 files changed, 44 insertions(+) create mode 100644 gitsrht/default_query.graphql create mode 120000 gitsrht/schema.graphqls diff --git a/gitsrht/app.py b/gitsrht/app.py index a37f453..525e047 100644 --- a/gitsrht/app.py +++ b/gitsrht/app.py @@ -27,6 +27,7 @@ class GitApp(ScmSrhtFlask): from gitsrht.blueprints.email import mail from gitsrht.blueprints.repo import repo from gitsrht.blueprints.stats import stats + from srht.graphql import gql_blueprint self.register_blueprint(plumbing) self.register_blueprint(porcelain) @@ -34,6 +35,7 @@ class GitApp(ScmSrhtFlask): self.register_blueprint(repo) self.register_blueprint(stats) self.register_blueprint(webhooks_notify) + self.register_blueprint(gql_blueprint) from gitsrht.repos import object_storage_enabled if object_storage_enabled: diff --git a/gitsrht/default_query.graphql b/gitsrht/default_query.graphql new file mode 100644 index 0000000..68231bb --- /dev/null +++ b/gitsrht/default_query.graphql @@ -0,0 +1,41 @@ +# Welcome to the SourceHut GraphQL explorer! +# You can use this to run test requests against the GraphQL API. +# To view the GraphQL schema, expand the button on the bottom of this page. +# Here's a sample query to get you started: +query { + # Fetch info about the authenticated user (you): + me { + # Grab their canonical name: + canonicalName + # And a list of repositories: + repositories(filter: { count: 5 }) { + # 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. Grab the id, name, and updated fields + # from each repository. + results { + id, name, updated + } + } + } + + # 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 " \ + # -H Content-Type:application/json \ + # -d '{"query": "{ me { canonicalName } }"}' \ + # https://git.sr.ht/query +} diff --git a/gitsrht/schema.graphqls b/gitsrht/schema.graphqls new file mode 120000 index 0000000..60b077d --- /dev/null +++ b/gitsrht/schema.graphqls @@ -0,0 +1 @@ +../api/graph/schema.graphqls \ No newline at end of file -- 2.38.4