{"action":"created","issue":{"url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/337","repository_url":"https://api.github.com/repos/mickhansen/graphql-sequelize","labels_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/337/labels{/name}","comments_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/337/comments","events_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/337/events","html_url":"https://github.com/mickhansen/graphql-sequelize/issues/337","id":181857097,"number":337,"title":"Adding limit to list/connection returns empty array","user":{"login":"chrissm79","id":1976169,"avatar_url":"https://avatars.githubusercontent.com/u/1976169?v=3","gravatar_id":"","url":"https://api.github.com/users/chrissm79","html_url":"https://github.com/chrissm79","followers_url":"https://api.github.com/users/chrissm79/followers","following_url":"https://api.github.com/users/chrissm79/following{/other_user}","gists_url":"https://api.github.com/users/chrissm79/gists{/gist_id}","starred_url":"https://api.github.com/users/chrissm79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrissm79/subscriptions","organizations_url":"https://api.github.com/users/chrissm79/orgs","repos_url":"https://api.github.com/users/chrissm79/repos","events_url":"https://api.github.com/users/chrissm79/events{/privacy}","received_events_url":"https://api.github.com/users/chrissm79/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-10-09T00:49:28Z","updated_at":"2016-10-09T22:23:49Z","closed_at":"2016-10-09T16:20:15Z","body":"When I query a connection without any arguments I get back a full list of edges (no limit applied). However, if I query a connection that includes the first argument (i.e., `employees(first:3)`), it returns an empty array. Taking a look at the logs, I can see that the limit is being applied in the query.\r\n\r\nModel:\r\n\r\n```javascript\r\nimport User from '../user/user-model';\r\n\r\nconst Company = sequelize.define('company', {\r\n  name: { type: Sequelize.STRING },\r\n  domain: { type: Sequelize.STRING },\r\n  createdAt: {\r\n    type: Sequelize.DATE,\r\n    field: 'created_at',\r\n  },\r\n  updatedAt: {\r\n    type: Sequelize.DATE,\r\n    field: 'updated_at',\r\n  },\r\n}, {\r\n  tableName: 'companies',\r\n  freezeTableName: true,\r\n});\r\n\r\nCompany.sync();\r\nCompany.Employees = Company.hasMany(User, { as: 'employees' });\r\n\r\nexport default Company;\r\n```\r\n\r\nType: \r\n\r\n```javascript\r\nconst fields = attributeFields(Company, {\r\n  globalId: true,\r\n});\r\n\r\nconst companyType = new GraphQLObjectType({\r\n  name: 'Company',\r\n  fields: assign(fields, {\r\n    // Same issue here...\r\n    // employees: {\r\n    //   type: new GraphQLList(userType),\r\n    //   args: {\r\n    //     limit: { type: GraphQLInt },\r\n    //   },\r\n    //   resolve: resolver(Company.Employees),\r\n    // },\r\n    employees: {\r\n      type: companyEmployeeConnection.connectionType,\r\n      args: companyEmployeeConnection.connectionArgs,\r\n      resolve: companyEmployeeConnection.resolve,\r\n    },\r\n  }),\r\n  interfaces: [nodeInterface],\r\n});\r\n\r\nexport default companyType;\r\n```\r\n\r\nConnection\r\n\r\n```javascript\r\nconst { sequelizeConnection } = relay;\r\n\r\nconst companyEmployeeConnection = sequelizeConnection({\r\n  name: 'companyEmployee',\r\n  nodeType: userType,\r\n  target: Company.Employees,\r\n  connectionFields: {\r\n    total: {\r\n      type: GraphQLInt,\r\n      resolve: ({source}) => {\r\n        return source.countEmployees();\r\n      },\r\n    }\r\n  },\r\n});\r\n\r\nexport default companyEmployeeConnection;\r\n```\r\n\r\n```graphql\r\n# returns empty array\r\n{\r\n  company {\r\n    employees(last: 5) {\r\n      edges {\r\n        node {\r\n          email\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\n# returns all employees\r\n{\r\n  company {\r\n    employees {\r\n      edges {\r\n        node {\r\n          email\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nBTW, I don't usually work w/ Sequelize but this package is fantastic!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/comments/252517239","html_url":"https://github.com/mickhansen/graphql-sequelize/issues/337#issuecomment-252517239","issue_url":"https://api.github.com/repos/mickhansen/graphql-sequelize/issues/337","id":252517239,"user":{"login":"chrissm79","id":1976169,"avatar_url":"https://avatars.githubusercontent.com/u/1976169?v=3","gravatar_id":"","url":"https://api.github.com/users/chrissm79","html_url":"https://github.com/chrissm79","followers_url":"https://api.github.com/users/chrissm79/followers","following_url":"https://api.github.com/users/chrissm79/following{/other_user}","gists_url":"https://api.github.com/users/chrissm79/gists{/gist_id}","starred_url":"https://api.github.com/users/chrissm79/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrissm79/subscriptions","organizations_url":"https://api.github.com/users/chrissm79/orgs","repos_url":"https://api.github.com/users/chrissm79/repos","events_url":"https://api.github.com/users/chrissm79/events{/privacy}","received_events_url":"https://api.github.com/users/chrissm79/received_events","type":"User","site_admin":false},"created_at":"2016-10-09T22:23:49Z","updated_at":"2016-10-09T22:23:49Z","body":"@mickhansen Found the issue... I'm working with a legacy DB which uses snake_case column names. I needed to add the `foreignKey` option when defining the `hasMany` relationship on the Company model. Either way it correctly queries the DB, however, without the `foreignKey` I was getting empty edges. \r\n\r\nThanks again, love the package!"}}
{"actor":{"display_login":"chrissm79"}}