simonw / datasette-graphql

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

Custom arguments on tables #58

Closed simonw closed 3 years ago

simonw commented 4 years ago

Relates to #16. How about if you could define custom arguments on tables which worked something like this:

trees(radius: {"lat": 37.78, "lng": -122.43, "km": 10}) {
  nodes {
    id
    name
  }
}

The radius here would be a custom argument defined in the plugin configuration.

Maybe it can be defined in terms of the where SQL clauses it adds?

simonw commented 4 years ago

Syntax something like:

plugins:
  datasette-graph-ql:
    databases:
      sf-trees:
        tables:
          arguments:
            radius:
              inputs:
                lat: float
                lng: float
                km: float
              where_sql: |-
                PtDistWithin(geometry, MakePoint(:lat ,:lng, 4326), :km * 1000)=TRUE
simonw commented 3 years ago

I think this is too similar to #16 - I'm going to solve this with custom queries instead, by making it so custom queries can state "I return the equivalent of an Entry" so nested GraphQL for foreign keys can work correctly.