Postgraphile - "Query Root must be provided" error message

1.4k Views Asked by At

We have an existing postgresql database with data and we are experimenting with postgraphile as a graphql API. We are running into an error that is leaving us scratching our head. the server runs fine but we get the following:

postgraphile -c postgres://username:password@localhost:5432/my_db                                                                

PostGraphile server listening on port 5000                                                                                                                 

  ‣ Connected to Postgres instance postgres://localhost:5432/my_db                                                                                          
  ‣ Introspected Postgres schema(s) public                                                                                                                      
  ‣ GraphQL endpoint served at http://localhost:5000/graphql                                                                                                    
  ‣ GraphiQL endpoint served at http://localhost:5000/graphiql                                                                                                  

* * *                                                                                                                                                           

An error occurred, it might be okay but it doesn't look like the error we were expecting... run with envvar 'DEBUG="graphile-build:warn"' to view the error     
An error occurred, it might be okay but it doesn't look like the error we were expecting... run with envvar 'DEBUG="graphile-build:warn"' to view the error     

Error: Query root type must be provided.                                                                                                                        
    at assertValidSchema (C:\Users\user\AppData\Roaming\npm\node_modules\postgraphile\node_modules\graphql\type\validate.js:78:11)                      
    at Object.validate (C:\Users\user\AppData\Roaming\npm\node_modules\postgraphile\node_modules\graphql\validation\validate.js:61:35)                  
    at parseQuery (C:\Users\user\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\http\createPostGraphileHttpRequestHandler.js:208:48)  
    at Promise.all.paramsList.map (C:\Users\user\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\http\createPostGraphileHttpRequestHandler.js:469:63)                                                                                                                                                  
    at Array.map (<anonymous>)                                                                                                                                  
    at requestHandler (C:\Users\user\AppData\Roaming\npm\node_modules\postgraphile\build\postgraphile\http\createPostGraphileHttpRequestHandler.js:435:52)                                                                                                                                   
    at <anonymous>                                                                                                                                              
    at process._tickCallback (internal/process/next_tick.js:188:7) 

and when we navigate to localhost:500/graphiql we see a a "no schema available" in the documentation explorer.

is the query root the publicschema? or what are we missing?

1

There are 1 best solutions below

0
On

Newer versions of PostGraphile have much more helpful error messages, often including a suggested solution. The "An error occurred" errors like those above now also contain a preview of the underlying error which helps with diagnosis.

There are instructions here on how to set the DEBUG environmental variable here: https://www.graphile.org/postgraphile/debugging/#debug-envvars

Here's how you might do it in Linux, macOS or Windows:

# Bash (Linux, macOS, etc)
export DEBUG="graphile-build:warn" postgraphile -c postgres://username:password@localhost:5432/my_db

# Windows Console
set DEBUG=graphile-build:warn & postgraphile -c postgres://username:password@localhost:5432/my_db

# Windows PowerShell
$env:DEBUG = "graphile-build:warn"; postgraphile -c postgres://username:password@localhost:5432/my_db