mickhansen / graphql-sequelize

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

GraphQLID for UUID #545

Closed galki closed 4 years ago

galki commented 6 years ago

apparently graphql-sequelize treats UUID fields as GraphQLString but mutations dont work this way. i have to do the below hack to make it work:

fields: () => Object.assign(attributeFields(MyModel), {
    id: { type: GraphQLID },
}),

graphql-sequelize: 5.4.2 sequelize: 4.13.2

mickhansen commented 6 years ago

graphql-sequelize doesn't support generating GraphQLID at all. commonly because you want a global id anyways.

galki commented 6 years ago

not too familiar with global ids, but are those for relay only?

mickhansen commented 6 years ago

They are used by any client with the concept of "nodes", that includes relay yes. An argument could be made for graphql-sequelize returning GraphQLID for primaryKey: true.

PR welcome, can be merged & published as a major bump.

galki commented 6 years ago

alright. can you at least reopen this issue please?

galki commented 6 years ago

@mickhansen im gonna go with number 2 but if you have another preference, please let me know.

  1. pass attribute.primaryKey to typeMapper.toGraphQL or
  2. do all logic in attributeFields.js

ps: im planning to do this for UUID and INTEGER

mickhansen commented 6 years ago

Option #2, typeMapper is just supposed to look at types

galki commented 6 years ago

FYI globalId: true doesnt seem to work for InputTypes:

Error: ProjectUserInput.id field type has a resolve property, but Input Types cannot define resolvers.

and input types are the only place i find myself doing this id hack:

export default models => new GraphQLInputObjectType({
    name: 'ProjectUserInput',
    fields: () => Object.assign(attributeFields(
        models.ProjectUser, { exclude: ['projectId'] }
    ), {
        id: { type: GraphQLID },
    }),
})
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.