title: GraphQL Cannot read property 'query' of undefined
body: <p>I cannot work out why I would get a query undefined when I know my definitions are correct. <code>graphiQL</code> is picking up my schemes without problems:</p>
  
  <p><a href="https://i.stack.imgur.com/XQHkT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XQHkT.png" alt="enter image description here"></a></p>
  
  <p>Auto complete works fine:</p>
  
  <p><a href="https://i.stack.imgur.com/GsoUu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GsoUu.png" alt="Before hitting alt+enter"></a></p>
  
  <p><a href="https://i.stack.imgur.com/2EqTa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2EqTa.png" alt="enter image description here"></a></p>
  
  <p><em>After hitting <code>ctrl+enter</code> all the fields are entered, see above.</em></p>
  
  <p>Then I execute the query and I'll get:</p>
  
  <pre><code>{
    "errors": [
      {
        "message": "Cannot read property 'query' of undefined",
        "locations": [
          {
            "line": 1,
            "column": 3
          }
        ],
        "path": [
          "allAwards"
        ]
      }
    ],
    "data": {
      "allAwards": null
    }
  }
  </code></pre>
  
  <h1>npm run graphql</h1>
  
  <pre><code>"graphql": "nodemon -r dotenv/config --experimental-modules --inspect=[9222] graphql_server.js",
  </code></pre>
  
  <h1>graphql_server.js</h1>
  
  <pre><code>import express from 'express'
  import pg from 'pg'
  import graphqlHTTP from 'express-graphql'
  import PAS from 'postgraphile-apollo-server'
  import AP from 'apollo-server-express'
  
  const { makeSchemaAndPlugin } = PAS
  const { ApolloServer } = AP
  
  const env = process.env.NODE_ENV || 'development'
  const dbHost = process.env.DB_HOST
  const dbPort = process.env.DB_PORT
  const dbName = process.env.DB_NAME
  const dbUser = process.env.DB_USER
  const dbPwd = process.env.DB_PWD
  const dbUrl = dbPwd
    ? `postgres://${dbUser}:${dbPwd}@${dbHost}:${dbPort}/${dbName}`
    : `postgres://${dbHost}:${dbPort}/${dbName}`
  
  const pgPool = new pg.Pool({
    connectionString: dbUrl,
  })
  
  async function main() {
    const { schema, plugin } = await makeSchemaAndPlugin(
      pgPool,
      'public', // PostgreSQL schema to use
      {
        // PostGraphile options, see:
        // https://www.graphile.org/postgraphile/usage-library/
      }
    )
  
    const server = new ApolloServer({
      schema,
      plugins: [plugin],
    })
    const app = express()
  
    app.use(
      '/graphql',
      graphqlHTTP({
        schema: schema,
        graphiql: true,
      })
    )
  
    server.applyMiddleware({ app })
  
    app.listen({ port: 4000 }, () =&gt; console.log(` Server ready at http://localhost:4000${server.graphqlPath}`))
  }
  
  main().catch(e =&gt; {
    console.error(e)
    process.exit(1)
  })
  </code></pre>
  
  <p>There are 2 rows currently in psql db for awards as well</p>
  
  <p><a href="https://i.stack.imgur.com/EeY4q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EeY4q.png" alt="enter image description here"></a></p>