mickhansen/dataloader-sequelize

Updating/Nuking cache after mutation

freynolds opened this issue ยท 2 comments

Hi, first of all, let me thank you for this, this code and graphql-sequelize are magic ๐ŸŽ‰

I've got a recurrent issue, which is an update of nested association when Creating/Updating the database.

Example

user {
  images
}

if I add a new image to the association, lets say its many to many between user and images, on the next request the server will return cached results

GQL definition like this

const user = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    images: {
      type: new GraphQLList(image),
      resolve:  resolver(models.User.Images)
    }
  })
})

My only current solution is to disable the data loader, like this (using ramda omit)

const user = new GraphQLObjectType({
  name: 'User',
  fields: () => ({
    images: {
      type: new GraphQLList(image),
      resolve: (source, args, context, info) => resolver(models.User.Images)(source, args, omit([EXPECTED_OPTIONS_KEY], context), info)
    }
  })
})

Clearly, this is wrong and it's creating some issues, I'm thinking I need to probably do something to the context on the Create/Update sequelize call, but haven't found any documentation pointing to that!

it sounds like you've created a dataloader instance globally instead of on a request basis. Can you show where you're creating such an instance?

If you do it on a request basis then it only caches and dataloads per request

๐Ÿคฏ
Well. I guess that is why I had to hack everything!
๐Ÿ‘ ๐Ÿ‘ ๐Ÿ‘
Thanks for that!