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

Support operationName #37

Closed simonw closed 4 years ago

simonw commented 4 years ago

Needed for GET #6 as well as POST.

https://graphql.org/learn/serving-over-http/#post-request

A standard GraphQL POST request should use the application/json content type, and include a JSON-encoded body of the following form:

{
  "query": "...",
  "operationName": "...",
  "variables": { "myVariable": "someValue", ... }
}

operationName and variables are optional fields. operationName is only required if multiple operations are present in the query.

simonw commented 4 years ago

Here's an example of operationName in the GitHub explorer:

GraphQL_API_Explorer___GitHub_Developer_Guide
query Query1 {
  viewer {
    login
  }
}

query Query2 {
  viewer {
    id
  }
}
simonw commented 4 years ago

https://datasette-graphql-demo.datasette.io/graphql?query=query%20Q1%20%7B%0A%20%20users_row%20%7B%0A%20%20%20%20login%0A%20%20%7D%0A%7D%0A%0Aquery%20Q2%20%7B%0A%20%20users_row%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D&operationName=Q2 doesn't work yet

query Q1 {
  users_row {
    login
  }
}

query Q2 {
  users_row {
    id
  }
}