mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

sequelize model comment => graphql field description #704

Closed floydspace closed 3 years ago

floydspace commented 3 years ago

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch graphql-sequelize@9.4.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/graphql-sequelize/lib/attributeFields.js b/node_modules/graphql-sequelize/lib/attributeFields.js
index 8a2a1c9..b86dc37 100644
--- a/node_modules/graphql-sequelize/lib/attributeFields.js
+++ b/node_modules/graphql-sequelize/lib/attributeFields.js
@@ -36,7 +36,8 @@ module.exports = function (Model) {
     }

     memo[key] = {
-      type: typeMapper.toGraphQL(type, Model.sequelize.constructor)
+      type: typeMapper.toGraphQL(type, Model.sequelize.constructor),
+      description: attribute.comment
     };

     if (memo[key].type instanceof _graphql.GraphQLEnumType || memo[key].type instanceof _graphql.GraphQLList && memo[key].type.ofType instanceof _graphql.GraphQLEnumType) {

This issue body was partially generated by patch-package.

floydspace commented 3 years ago

Hi @mickhansen, does it make sense to map sequelize model comment property to graphql field description?

mickhansen commented 3 years ago

Hi @floydspace. There's an option to do it: options.commentToDescription https://github.com/mickhansen/graphql-sequelize/blob/master/src/attributeFields.js#L63

floydspace commented 3 years ago

Thank you @mickhansen , my bad to not read the documentation. πŸ€¦β€β™‚οΈ Good job.

mickhansen commented 3 years ago

No worries, not even sure it's documented anywhere hah