Closed ArturBaybulatov closed 5 years ago
You've left out the most relevant piece of code, the schema implementation with resolvers.
Example code in the repository I provided, in the schema.js
file. If I understood you right
This line is incorrect it needs to be defined as an association rather than a direct model, that's why you are getting all Products
this will change to
resolve: graphqlSequelize.resolver(models.Category.associations.Product),
@ArturBaybulatov Was looking for the code for the specific resolver. However @Aukhan provided the answer
@mickhansen I would like to play my part in keeping this repo moving, we are using this repo in two major products now, keeping all opinions aside, I feel like this and Sequelize are great libraries and must be kept alive. Please let me know if i could help out with triaging, setting up release goals and contribute code. There's a bunch of issues that can be closed, some need more information while a few are real. Thanks !
@Aukhan That sounds great, can always use help.
thanks @mickhansen, I guess this particular issue can be closed
@Aukhan Thanks for the response! It worked for me with the following line (with "Products", not "Product")
resolve: graphqlSequelize.resolver(models.Category.associations.Products),
@ArturBaybulatov correct, that's because it's a many
relationship and sequelize pluralizes it but I hope you get the idea.
I got an example project, where I've set up a simple schema:
https://github.com/ArturBaybulatov/_nodejs-playground/tree/master/graphql-sequelize-basic-example (sample sqlite DB included; clone the repo,
cd graphql-sequelize-basic-example
, runnpm install
, thennpm start
to start the project)So, when I query:
I expect to get only products from that category (with ID 8), but I get everything from a table:
Is there a way to fix this? Have I defined the schema the wrong way? Thanks