Skip to main content

A GraphQL endpoint for Datasette

Project description

datasette-graphql

PyPI Changelog License

A GraphQL endpoint for Datasette

Work in progress alpha - this has many missing features.

Try out a live demo at datasette-graphql-demo.datasette.io/graphql.

Installation

Install this plugin in the same environment as Datasette.

$ pip install datasette-graphql

Usage

This plugin up /graphql as a GraphQL endpoint for the first attached database.

Querying for tables and columns

Individual tables can be queried like this:

{
  repos {
    id
    full_name
    description
  }
}

Accessing nested objects

If a column is a foreign key to another table, you can request columns of that table using a nested query like this:

{
  repos {
    id
    full_name
    owner {
      id
      login
    }
  }
}

Filtering tables

You can filter the rows returned for a specific table using the filters: argument. This accepts a list of filters, where a filter is a string of the form column=value or column__op=value. For example, to return just repositories with the Apache 2 license and more than 10 stars:

{
  repos(filters: ["license=apache-2.0", "stargazers_count__gt=10"]) {
    full_name
    stargazers_count
    license {
      key
    }
  }
}

This is the same format used for querystring arguments to the Datasette table view, see column filter arguments in the Datasette documentation.

Auto camelCase

The names of your columns and tables default to being matched by their representations in GraphQL.

If you have tables with names_like_this you may want to work with them in GraphQL using namesLikeThis, for consistency with GraphQL and JavaScript conventions.

You can turn on automatic camelCase using the "auto_camelcase" plugin configuration setting in metadata.json, like this:

{
    "plugins": {
        "datasette-graphql": {
            "auto_camelcase": true
        }
    }
}

Still to come

See issues for a full list. Planned improvements include:

  • Pagination
  • Canned query support
  • Ability to allowlist specific tables, views and canned queries

Development

To set up this plugin locally, first checkout the code. Then create a new virtual environment:

cd datasette-graphql
python3 -mvenv venv
source venv/bin/activate

Or if you are using pipenv:

pipenv shell

Now install the dependencies and tests:

pip install -e '.[test]'

To run the tests:

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasette-graphql-0.1a4.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

datasette_graphql-0.1a4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file datasette-graphql-0.1a4.tar.gz.

File metadata

  • Download URL: datasette-graphql-0.1a4.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for datasette-graphql-0.1a4.tar.gz
Algorithm Hash digest
SHA256 faa770c5900cc18a30466876656c9e0d15aa5803c81a834899db31d797440a91
MD5 3addeb0f11e30a72cb56e7829cab57d3
BLAKE2b-256 c28abd2e3bebf0bd05a93c90ed8029c2630a20c3cf329528e51e3ba3ebb76150

See more details on using hashes here.

File details

Details for the file datasette_graphql-0.1a4-py3-none-any.whl.

File metadata

  • Download URL: datasette_graphql-0.1a4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for datasette_graphql-0.1a4-py3-none-any.whl
Algorithm Hash digest
SHA256 0e5f9b4581d7d9594d99a22af69654376ee047a5f2b64a62ba9a616197b308ef
MD5 2583712f6f2d677c6360200c3ee468f2
BLAKE2b-256 1b94ff914858adec65aeae5aed7c1d48ad433849e4f88f16ce57da8a48977004

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page