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

Get GraphiQL introspection / autocomplete / documentation working #1

Closed simonw closed 4 years ago

simonw commented 4 years ago

Right now I'm not seeing any of the autocomplete or documentation in the GraphiQL desktop app.

GraphiQL
simonw commented 4 years ago

Starlette's implementation may hold some clues: https://github.com/encode/starlette/blob/master/starlette/graphql.py

simonw commented 4 years ago

The demo at https://graphql.org/swapi-graphql kicks off a POST on first load with this body:

{"query":"\n    query IntrospectionQuery {\n      __schema {\n        \n        queryType { name }\n        mutationType { name }\n        subscriptionType { name }\n        types {\n          ...FullType\n        }\n        directives {\n          name\n          description\n          \n          locations\n          args {\n            ...InputValue\n          }\n        }\n      }\n    }\n\n    fragment FullType on __Type {\n      kind\n      name\n      description\n      fields(includeDeprecated: true) {\n        name\n        description\n        args {\n          ...InputValue\n        }\n        type {\n          ...TypeRef\n        }\n        isDeprecated\n        deprecationReason\n      }\n      inputFields {\n        ...InputValue\n      }\n      interfaces {\n        ...TypeRef\n      }\n      enumValues(includeDeprecated: true) {\n        name\n        description\n        isDeprecated\n        deprecationReason\n      }\n      possibleTypes {\n        ...TypeRef\n      }\n    }\n\n    fragment InputValue on __InputValue {\n      name\n      description\n      type { ...TypeRef }\n      defaultValue\n    }\n\n    fragment TypeRef on __Type {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n                ofType {\n                  kind\n                  name\n                  ofType {\n                    kind\n                    name\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  ","operationName":"IntrospectionQuery"}

Mine does the same thing - and gets a response back as well.

Here's the response from mine against my https://github-to-sqlite.dogsheep.net/github.db demo database: https://gist.github.com/simonw/81da97ce97240e54b2b359411122cfa9

And here's the response from the swapi-graphql demo: https://gist.github.com/simonw/d93b20b5cbeb9cd058f4810e5190a3eb

simonw commented 4 years ago

The SWAPI one starts like this:

{
    "data": {
        "__schema": {
            "queryType": {
                "name": "Root"

Mine starts like this:

{
    "__schema": {
        "queryType": {
            "name": "Query"
        },
        "mutationType": null,

Looks like I'm missing the "data" top-level key.

simonw commented 4 years ago

That fixed it!

GraphiQL_and_my-schema_json