Chatie / db

Database for Chatie
https://www.chatie.io
Apache License 2.0
0 stars 0 forks source link

Sync from Mutation with the Subscription #12

Closed huan closed 6 years ago

huan commented 6 years ago

after we created the new item in the Store, the subscription need to be notified from the WebSocket, so we have to wait a while after the creation, or we will get an empty itemDict.

SOLUTION: wait for event loop to finished all queued tasks UPDATE: It seems that the apollo-client might have some bug when we are running subscribeToMore() then with a mutate() at the same time. So we have to wait for the subscription initialized before we do mutate().

https://travis-ci.org/Chatie/db/builds/356676518

# read() with exist id
02:16:59 VERB LocalServer deleteAll(model=true)
02:16:59 VERB LocalServer deleteAll(model=Giftie)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer deleteAll() get 0 items for Giftie
02:16:59 SILL LocalServer deleteAll() deleted all items for Giftie
02:16:59 VERB LocalServer deleteAll(model=Botie)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer deleteAll() get 0 items for Botie
02:16:59 SILL LocalServer deleteAll() deleted all items for Botie
02:16:59 VERB LocalServer deleteAll(model=Hostie)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer deleteAll() get 0 items for Hostie
02:16:59 SILL LocalServer deleteAll() deleted all items for Hostie
02:16:59 VERB LocalServer deleteAll(model=User)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer deleteAll() get 0 items for User
02:16:59 SILL LocalServer deleteAll() deleted all items for User
02:16:59 VERB LocalServer createUser(email=email-1426119@email.com, nickname=nickname-1426119, name=name-1426119)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer createUser() = cjf1vyz9u006v01899eqyv39q
02:16:59 VERB LocalServer generateUserToken(userId=cjf1vyz9u006v01899eqyv39q, expirationInSeconds=undefined)
02:16:59 VERB LocalServer graphcool()
02:16:59 SILL LocalServer generateUserToken() = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MjQyNzcwMTksImlhdCI6MTUyMTY4NTAxOSwicHJvamVjdElkIjoiY2pmMXZ5YWI4MDAwNDAxODkwbWc1djE4dyIsInVzZXJJZCI6ImNqZjF2eXo5dTAwNnYwMTg5OWVxeXYzOXEiLCJtb2RlbE5hbWUiOiJVc2VyIn0.D-_uSrnet2LJ1z7l5-OXZK8qhV1oa64cLxv9D4cBPrI
02:16:59 VERB LocalServer endpoints()
02:16:59 VERB LocalServer info()
02:16:59 VERB Apollo getApolloClient(token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MjQyNzcwMTksImlhdCI6MTUyMTY4NTAxOSwicHJvamVjdElkIjoiY2pmMXZ5YWI4MDAwNDAxODkwbWc1djE4dyIsInVzZXJJZCI6ImNqZjF2eXo5dTAwNnYwMTg5OWVxeXYzOXEiLCJtb2RlbE5hbWUiOiJVc2VyIn0.D-_uSrnet2LJ1z7l5-OXZK8qhV1oa64cLxv9D4cBPrI, endpoints={"relay":"http://localhost:60000/relay/v1/cjf1vyab8000401890mg5v18w","simple":"http://localhost:60000/simple/v1/cjf1vyab8000401890mg5v18w","subscriptions":"ws://localhost:60000/subscriptions/v1/cjf1vyab8000401890mg5v18w","system":"http://localhost:60000/system"})
02:16:59 SILL Apollo getApolloClient() connected
02:16:59 VERB LocalServer rootToken()
02:16:59 SILL LocalServer rootToken() = eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MjE2ODQ5OTIsImNsaWVudElkIjoiY2pmMXZ5NHFqMDAwMDAxODlzenNwbDdpdiIsInByb2plY3RJZCI6ImNqZjF2eWFiODAwMDQwMTg5MG1nNXYxOHciLCJwZXJtYW5lbnRBdXRoVG9rZW5JZCI6ImNqZjF2eWVrNDAwMnEwMTg5cTA3aXprZzkifQ.-HW04kbOiJ95CJBpbJhhLbUWJd04yko4K_v3Dv2DHgM
02:16:59 VERB Db constructor(token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MjQyNzcwMTksImlhdCI6MTUyMTY4NTAxOSwicHJvamVjdElkIjoiY2pmMXZ5YWI4MDAwNDAxODkwbWc1djE4dyIsInVzZXJJZCI6ImNqZjF2eXo5dTAwNnYwMTg5OWVxeXYzOXEiLCJtb2RlbE5hbWUiOiJVc2VyIn0.D-_uSrnet2LJ1z7l5-OXZK8qhV1oa64cLxv9D4cBPrI)
02:16:59 VERB Db open()
02:16:59 SILL Db init() initializing apollo client...
02:16:59 VERB Apollo getApolloClient(token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1MjQyNzcwMTksImlhdCI6MTUyMTY4NTAxOSwicHJvamVjdElkIjoiY2pmMXZ5YWI4MDAwNDAxODkwbWc1djE4dyIsInVzZXJJZCI6ImNqZjF2eXo5dTAwNnYwMTg5OWVxeXYzOXEiLCJtb2RlbE5hbWUiOiJVc2VyIn0.D-_uSrnet2LJ1z7l5-OXZK8qhV1oa64cLxv9D4cBPrI, endpoints={"relay":"http://localhost:60000/relay/v1/cjf1vyab8000401890mg5v18w","simple":"http://localhost:60000/simple/v1/cjf1vyab8000401890mg5v18w","subscriptions":"ws://localhost:60000/subscriptions/v1/cjf1vyab8000401890mg5v18w","system":"http://localhost:60000/system"})
02:16:59 SILL Apollo getApolloClient() connected
02:16:59 VERB Store constructor()
02:16:59 VERB HostieStore constructor()
02:16:59 VERB Store open()
02:16:59 VERB Store initSubscribeToMore(itemQuery)
02:16:59 VERB Store initSubscription(itemQuery)
02:16:59 VERB HostieStore add(newHostie{name:name-5196280})
02:16:59 VERB Store mutationUpdateFn(mutationType=CREATED, mutationDataKey=createHostie)
Unhandled error GraphQL error: Cannot return null for non-nullable type (line 13, column 3):
  owner {
  ^ Error: GraphQL error: Cannot return null for non-nullable type (line 13, column 3):
  owner {
  ^
    at ApolloError.Error (native)
    at new ApolloError (/home/travis/build/Chatie/db/node_modules/apollo-client/errors/ApolloError.js:34:28)
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:273:41
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:659:17
    at Array.forEach (native)
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:658:18
    at Map.forEach (native)
    at QueryManager.broadcastQueries (/home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:653:22)
    at Object.next (/home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:687:31)
    at Object.next (/home/travis/build/Chatie/db/node_modules/zen-observable/zen-observable.js:158:20)
02:16:59 VERB Store mutationUpdateFn(mutationType=CREATED, mutationKey=createHostie), (proxy, {data})
02:16:59 VERB Store mutationUpdateFn() call proxy.readQuery() before any query had been executed.
02:16:59 VERB Store mutationUpdateFn() proxy.readQuery() return empty???
02:16:59 VERB Store read(id=cjf1vyzfk00760189ysrfgx4e)
02:16:59 SILL Store get itemDict()
not ok 5 Error: Store.read(id=cjf1vyzfk00760189ysrfgx4e) not found!
  ---
    operator: fail
    at: Object.<anonymous> (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:107:19)
    stack: |-
      Error: Error: Store.read(id=cjf1vyzfk00760189ysrfgx4e) not found!
          at Test.assert [as _assert] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:225:54)
          at Test.bound [as _assert] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:77:32)
          at Test.fail (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:318:10)
          at Test.bound [as fail] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:77:32)
          at Object.<anonymous> (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:107:19)
          at throw (native)
          at rejected (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:6:65)
          at process._tickCallback (internal/process/next_tick.js:109:7)
  ...
02:16:59 VERB Store close()
02:16:59 VERB Db close()
huan commented 6 years ago
# read() with exist id
05:09:10 SILL Apollo getApolloClient() connected
05:09:10 VERB Store constructor()
05:09:10 VERB HostieStore constructor()
05:09:10 VERB Store open()
05:09:10 VERB Store initSubscribeToMore(itemQuery)
05:09:10 VERB Store initSubscription(itemQuery)
05:09:10 VERB HostieStore create(newHostie={"name":"name-8217636","key":"key-8217636","ownerId":"cjf224evh00700131q0t5z4he"})
05:09:10 VERB Store mutationUpdateFn(mutationType=CREATED, mutationDataKey=createHostie)
05:09:10 SILL HostieStore create() apollo.mutate()
Unhandled error GraphQL error: Cannot return null for non-nullable type (line 13, column 3):
  owner {
  ^ Error: GraphQL error: Cannot return null for non-nullable type (line 13, column 3):
  owner {
  ^
    at new ApolloError (/home/travis/build/Chatie/db/node_modules/apollo-client/errors/ApolloError.js:34:28)
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:273:41
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:659:17
    at Array.forEach (<anonymous>)
    at /home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:658:18
    at Map.forEach (<anonymous>)
    at QueryManager.broadcastQueries (/home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:653:22)
    at Object.next (/home/travis/build/Chatie/db/node_modules/apollo-client/core/QueryManager.js:687:31)
    at SubscriptionObserver.next (/home/travis/build/Chatie/db/node_modules/zen-observable/zen-observable.js:158:20)
    at /home/travis/build/Chatie/db/node_modules/apollo-link-dedup/src/dedupLink.ts:60:43
05:09:10 VERB Store mutationUpdateFn(mutationType=CREATED, mutationDataKey=createHostie), (proxy, {data})
05:09:10 VERB Store mutationUpdateFn() call proxy.readQuery() before any query had been executed.
05:09:10 SILL HostieStore create() apollo.mutate() done
createHostie:  { name: 'name-8217636',
  __typename: 'Hostie',
  key: 'key-8217636',
  id: 'cjf224f2p007b013183ixz6qx',
  note: null,
  owner: 
   { email: 'email-6952214@email.com',
     id: 'cjf224evh00700131q0t5z4he',
     name: 'name-6952214',
     __typename: 'User' } }
05:09:10 VERB Store read(id=cjf224f2p007b013183ixz6qx)
05:09:10 SILL Store get itemDict()
not ok 7 Error: Store.read(id=cjf224f2p007b013183ixz6qx) not found!
  ---
    operator: fail
    at: Object.<anonymous> (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:111:19)
    stack: |-
      Error: Error: Store.read(id=cjf224f2p007b013183ixz6qx) not found!
          at Test.assert [as _assert] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:225:54)
          at Test.bound [as _assert] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:77:32)
          at Test.fail (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:318:10)
          at Test.bound [as fail] (/home/travis/build/Chatie/db/node_modules/tape/lib/test.js:77:32)
          at Object.<anonymous> (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:111:19)
          at Generator.throw (<anonymous>)
          at rejected (/home/travis/build/Chatie/db/src/hostie/hostie-store.spec.ts:6:65)
          at <anonymous>
          at process._tickCallback (internal/process/next_tick.js:118:7)
  ...
05:09:10 VERB Store close()
05:09:10 VERB Db close()
huan commented 6 years ago

Finally, the CI turned green.

SOLUTION: It seems that the apollo-client might have some bug when we are running subscribeToMore() then with a mutate() at the same time. So we have to wait for the subscription initialized before we do mutate().