simonw / datasette-graphql

Datasette plugin providing an automatic GraphQL API for your SQLite databases
https://datasette-graphql-demo.datasette.io/
Apache License 2.0
101 stars 6 forks source link

graphql(query) template function should optionally support variables #54

Closed simonw closed 4 years ago

simonw commented 4 years ago

https://github.com/simonw/datasette-template-sql supports named parameters:

        {% for til in sql("select * from til where topic = :topic", {"topic": row.topic}) %}
            <li><a href="{{ til.url }}">{{ til.title }}</a> - {{ til.created[:10] }}</li>
        {% endfor %}

The equivalent for the graphql() function from #50 would be to support GraphQL variables.

simonw commented 4 years ago

Syntax:

{% set user = graphql("""
query ($id: Int) {
    users_row(id: $id) {
        name
        login
        avatar_url
    }
}
""", database="github", variables={"id": 9599})["users_row"] %}