rexxars / sql-to-graphql

Generate a GraphQL API based on your SQL database structure
MIT License
592 stars 73 forks source link

MySQL JSON column type throws error. #42

Open tankerkiller125 opened 8 years ago

tankerkiller125 commented 8 years ago
{ tableName: 'recipes',
  columnName: 'ingredients',
  ordinalPosition: 5,
  isNullable: 'NO',
  dataType: 'json',
  columnKey: '',
  columnType: 'json',
  columnComment: '' }
Unhandled rejection Error: Type "json" not recognized
    at getType (/usr/lib/node_modules/sql-to-graphql/steps/column-to-object.js:127:19)
    at columnToObject (/usr/lib/node_modules/sql-to-graphql/steps/column-to-object.js:16:8)
    at /usr/lib/node_modules/sql-to-graphql/steps/table-to-object.js:16:16
    at Array.map (native)
    at Object.tableToObject (/usr/lib/node_modules/sql-to-graphql/steps/table-to-object.js:15:32)
    at onTableDataCollected (/usr/lib/node_modules/sql-to-graphql/cli.js:127:23)
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:726:13
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:52:16
    at done (/usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:246:17)
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:44:16
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:723:17
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:167:37
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:726:13
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:52:16
    at done (/usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:246:17)
    at /usr/lib/node_modules/sql-to-graphql/node_modules/async/lib/async.js:44:16
rexxars commented 8 years ago

Unsure what we can do about JSON types, to be honest. If I understand correctly, JSON fields doesn't have any schema, and thus representing them in a strict API such as GraphQL will be kind of tricky, if not impossible.

tankerkiller125 commented 8 years ago

My way of doing it for now is that I converted it to a standard text type. And then I just have GraphQL return the entire JSON statement. Allowing the client to handle the JSON itself.