graphile / postgraphile-apollo-server

41 stars 5 forks source link

List Queries don't seem to work #9

Open akeemphilbert opened 4 years ago

akeemphilbert commented 4 years ago

I have it setup and when I try to query a specific item that seems to work:

query MyQuery {
  educationalStage (educationalStageId:1) {
    title
  }
}

and it returns the expected result

{
  "data": {
    "educationalStage": {
      "title": "Early Childhood"
    }
  }
}

but when I try to do the list query the total count is 0 which is odd because there are records there evidenced by my previous search

query MyQuery {
  educationalStages {
    totalCount
  }
}

result

{
  "data": {
    "educationalStages": {
      "totalCount": 0
    }
  }
}

Setup code (note I've tried without the plugins as well no dice, I've also tried without merging the other schema)

const { schema, plugin } =  await makeSchemaAndPlugin(
        pgPool,
        'public', // PostgreSQL schema to use
        {
            // watchPg: true,
            // graphiql: true,
            // enhanceGraphiql: true,
            subscriptions: true,
            retryOnInitFail: true,
            dynamicJson: true,
            setofFunctionsContainNulls: false,
            ignoreRBAC: false,
            ignoreIndexes: true,
            showErrorStack: true,
            extendedErrors: ['hint', 'detail', 'errcode'],
            appendPlugins: [require("@graphile-contrib/pg-many-to-many"),require("@graphile-contrib/pg-simplify-inflector")]
        }
    );

    const server = new ApolloServer({
        schema: mergeSchemas({schemas:[madeExecutableSchema,schema]}),
        playground: true,
        plugins: [plugin]
    });

dependencies

{
    "@graphile-contrib/pg-many-to-many": "^1.0.0",
    "@graphile-contrib/pg-simplify-inflector": "^6.0.0",
    "apollo-server-express": "^2.16.1",
    "body-parser": "^1.19.0",
    "elasticsearch": "^16.7.1",
    "express": "^4.17.1",
    "graphql": "^15.3.0",
    "graphql-tools": "^6.1.0",
    "pg": "^8.3.3",
    "postgraphile": "^4.8.0",
    "postgraphile-apollo-server": "^0.1.1"
  }
benjie commented 4 years ago

I've updated your issue as it was hard to read the code blocks before, you might like to review the edit so you can improve future issues :+1:

I attempted to reproduce your issue but could not. My attempt can be found here:

https://github.com/graphile/postgraphile-example-apollo-server/commit/b6d212c6d8db5299e2d843f570cfc08aa901481c

Running the server as:

DATABASE_URL="graphile_starter" SCHEMA_NAMES="app_public" node server.js

Issuing this query:

{
  userByUsername(username:"benjie") {
    id
  }
  users {
    totalCount
  }
}

Produced this result:

{
  "data": {
    "userByUsername": {
      "id": "6d7f9b81-cb8a-4536-8cc9-6fcf107e80a7"
    },
    "users": {
      "totalCount": 1
    }
  }
}

This is as expected. (I used the graphile_starter database from the Graphile Starter project.)

Please create a working reproduction (with database) as a pull request against the https://github.com/graphile/postgraphile-example-apollo-server repository and then we can take another look.