Skip to content

Instantly share code, notes, and snippets.

@darrensapalo
Last active February 20, 2021 06:16
Show Gist options
  • Select an option

  • Save darrensapalo/d445b1d1cfc9452bf1e67fd3beb782f7 to your computer and use it in GitHub Desktop.

Select an option

Save darrensapalo/d445b1d1cfc9452bf1e67fd3beb782f7 to your computer and use it in GitHub Desktop.
Tinkering with Faith

Context

Faith: the gist is I wanted to send a response (just to test) when everything completed, but it no longer did subscription 'complete' callback after I added graphql mutations/queries. the queries/mutations work and reflect in the DB. do i be missing somethin like am I using the apollo functions wrong?

Code snippet

  const process$ = of(configuration).pipe(
      tap((config) => (configuration = config)),
      concatMap((configuration) =>
        from(configuration.operations).pipe(
            concatMap((operation) =>
              mapProcessingOperation(operation, configuration),
            ),
        ),
      ),
      toArray(),
      mergeMapTo(getAllOutputFiles(processID)),
      mergeMap((filePaths) => from(filePaths)),
      mergeMap((filePath) => uploadToS3(s3, filePath, processID, userID)),
      toArray(),
      mergeMap((filePaths) => akpService$.pipe(
          mergeMap((service) => {
            const updateStatusVars = {
              process_id: processID,
              changes: {
                status: 'success',
                s3_url: filePaths[0],
              },
            };
            return performUpdateProcess(service, updateProcessMutation, updateStatusVars);
          })),
      ),
  );

I think maybe one of your outer observables may not have completed yet? Not sure.

Analyzing the code...

  • of(configuration) should complete, naturally, since it's a single value.
  • from(configuration.operations) should also complete, as it is bounded by the config yaml definition.
  • toArray() transforms it into a single emission, which we know will complete because of the first two source observables are bounded/will complete.
  • ❓ does the observable constructor definition for getAllOutputFiles have a subscriber.complete() call? ✅ Yes, it does.
  • from(filePaths) should complete because it comes from an array.
  • ❓ does the observable constructor definition for uploadToS3 have a subscriber.complete() call? ✅ Yes, it does.
  • Assuming it does have a complete call, then the succeeding toArray() will be able to execute (since the whole list of emissions will be ready because of the completes).
  • ❓ Does the code run at this point, in the mergeMap((service) => { } code area? Does performUpdateProcess run?
  • ❓ does the observable constructor definition for performUpdateProcess have a subscribe.complete() call? ✅ Yes, it does.

Clarification

Faith: I checked the performApolloMutation function reference and it seems like it passes thru subscriber.complete() right after subscriber.next() naman?

What does this mean? what does it seems like it passes thru mean?

Recommendations

  • ❓ Have you begun to use VS Code's debugger?
  • Try to see as well ifrxjs-spy might help you debug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment