Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Sequelize BOOLEAN for boolean fields #31

Closed
wants to merge 7 commits into from

Conversation

renato
Copy link

@renato renato commented Mar 11, 2020

SQLite boolean fields are currently being typed as Sequelize's NUMERIC type (https://github.com/bradleyboy/tuql/blob/master/src/builders/definitions.js#L22) but they end up as a String type on the GraphQL API.

I'm using Sequelize's BOOLEAN instead and it's working as expected.

const resolvers = {
  Mutation: {
    updateTimer: fn => async (obj, values, info) => {
      doSomethingBefore()
      const ret = await fn(obj, values, info)
      doSomethingAfter()
      return ret
    }
  }
}
createThings(input: [ThingCreateInput!]): [Thing]
deleteThings(where: SequelizedJSON!): GenericResponse
…nd arg, like:

{
  Mutation: {
    updateTimer: fn => async (obj, values, info) => {
        // something before
        const ret = await fn(obj, values, info)
        // something after
      return ret
    }
  },
  Query: {
    now: {
      type: GraphQLString,
      resolve: () => new Date().toISOString()
    }
  }
}
Copy link
Owner

@bradleyboy bradleyboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reviewing this way late @renato – so no obligation to respond, but there appears to be more than the bool change in this PR and just curious what the goal of the customSchema stuff is so I can document it.

@@ -37,7 +40,7 @@ export default columns => {
field: column.name,
allowNull: column.notnull === 0 || column.dflt_value !== null,
defaultValue: column.dflt_value,
autoIncrement: column.type === 'INTEGER' && column.pk === 1,
autoIncrement: column.type === 'integer' && column.pk === 1,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC the case of this is not consistent, to be safe we should column.type.toLowerCase() perhaps?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up using a totally custom schema, but the idea of the customSchema was to extend the default types/resolvers with custom ones, I tried to give somes examples on the commit messages.

Looking at the commit dates I think only the first commit was actually intended to be part of the PR, sorry about that.

About the integer, I've changed to the case that worked for me at the time, I'm not sure it's inconsistent but it's possible.

@renato renato closed this Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants