https://www.prisma.io/ logo
Join SlackCommunities
Powered by
# orm-help
  • i

    inno

    10/11/2019, 8:22 AM
    well i guess when the client is restarted initially you can just check if stuff was deleted. then continue listening
  • j

    Joakim Karlsson

    10/11/2019, 8:24 AM
    how do i check if stuff was deleted when i was not listening if it’s gone when i connect again? ( are you saying the subscriber should have it’s own copy of the prisma state to be able to diff whats missing from the db at start?)
  • j

    Joakim Karlsson

    10/11/2019, 8:25 AM
    when we issue a delete mutation it gets removed from the database so how would i get the info that those records were removed when i re-subscribe
  • j

    Joakim Karlsson

    10/11/2019, 8:27 AM
    what we need to achieve is a reliable and durable way to notify a external service that something was updated/created/deleted in prisma. pref a catchup mechanic or a transaction log of whats been deleted so we don’t miss them and the external service becomes out of sync
  • j

    Joakim Karlsson

    10/11/2019, 8:30 AM
    what we have came up with so far was creating a DB trigger that on update, delete and insert for a specific table, insert a change record in a auxiliary table, then have a daemon read from that table and perform webhooks to the external service. this would ensure durability and we won’t miss any updates since it’s done in the DB and if the DB isn’t running. nothing is modifying anyway.
  • j

    Joakim Karlsson

    10/11/2019, 8:30 AM
    But as you can probably see, that is not pretty at all and requires making a new custom service and ad-hoc triggers in the DB
  • i

    inno

    10/11/2019, 8:40 AM
    well another way i guess is you can create an intermediate service that checks if the subscribed users have received published subscriptions of not then, i guess the client checks if it has any new subscriptions or messages on the service''s queue/table. so mybe once the client receives and confirm you can delete the records.
  • j

    Joakim Karlsson

    10/11/2019, 8:44 AM
    https://github.com/prisma/prisma/issues/3852
    • 1
    • 1
  • j

    Joakim Karlsson

    10/11/2019, 8:44 AM
    so i guess Subscriptions is totally of the table
  • j

    Joakim Karlsson

    10/11/2019, 8:46 AM
    https://github.com/prisma/prisma/issues/3304
  • j

    Joakim Karlsson

    10/11/2019, 8:47 AM
    updateMany and deleteMany Mutations Do Not Fire Subscriptions
  • j

    Joakim Karlsson

    10/11/2019, 8:48 AM
    https://github.com/prisma/prisma/issues/3303
    Cascade Deletion Does Not Fire Subscriptions
  • j

    Joakim Karlsson

    10/11/2019, 8:50 AM
    https://github.com/prisma/prisma/issues/2327
    Currently, batch mutations don't fire subscription events.
  • i

    inno

    10/11/2019, 8:54 AM
    well you can also create custom subscriptions
  • j

    Joakim Karlsson

    10/11/2019, 8:55 AM
    do elaborate please
  • i

    inno

    10/11/2019, 8:59 AM
    ok, i think this post might help: https://www.prisma.io/docs/1.10/tutorials/build-graphql-servers/development/build-a-realtime-graphql-server-with-subscriptions-ien5es6ok3
  • j

    Joakim Karlsson

    10/11/2019, 9:03 AM
    so you are saying that by creating the subscription in the server and not just via the client we won’t be affected by the bugs above where it does not fire under load or updateMany, deleteMany & during batch mutations?
  • j

    Joakim Karlsson

    10/11/2019, 9:04 AM
    and how would it become durable this time?
  • j

    Joakim Karlsson

    10/11/2019, 9:09 AM
    as in. how do we get notified about stuff that got deleted when the subscriber wasn’t connected as they are no longer in the database when it reconnects
  • i

    inno

    10/11/2019, 9:09 AM
    that will depend on how the custom subscriptions are implemented
  • j

    Joakim Karlsson

    10/11/2019, 9:11 AM
    could you be more specific please
  • j

    Joakim Karlsson

    10/11/2019, 9:13 AM
    tkae this example
    Copy code
    const resolvers = {
      Query: {
        // ... like before
      },
      Mutation: {
        // ... like before
      },
      Subscription: {
        publications: {
          // ... like before
        },
        postDeleted: {
          subscribe: (parent, args, ctx, info) => {
            const selectionSet = `{ previousValues { id title } }`
            return <http://ctx.db.subscription.post|ctx.db.subscription.post>(
              {
                where: {
                  mutation_in: ['DELETED'],
                },
              },
              selectionSet,
            )
          },
          resolve: (payload, args, context, info) => {
            return payload ? payload.post.previousValues : payload
          },
        },
      },
    }
  • j

    Joakim Karlsson

    10/11/2019, 9:13 AM
    are you saying we should insert code here that does things to make it durable?
  • i

    inno

    10/11/2019, 9:16 AM
    yes you can create checks/validations in here before execution
  • j

    Joakim Karlsson

    10/11/2019, 9:16 AM
    ok, but will these fire even if there actually isn’t anyone connected to the subscription?
  • i

    inno

    10/11/2019, 9:20 AM
    u could also store the events in a table/log, then wen the clients start up it checks the events on the table/log
  • j

    Joakim Karlsson

    10/11/2019, 9:21 AM
    ok, then i just have one final question
  • j

    Joakim Karlsson

    10/11/2019, 9:22 AM
    if we do this
  • j

    Joakim Karlsson

    10/11/2019, 9:22 AM
    how do we make sure it only triggers once
  • j

    Joakim Karlsson

    10/11/2019, 9:22 AM
    say we are running 6x of the application and 3x of prisma
1...319320321...637Latest