How to use the @keystonejs/fields.Relationship.resolveBacklinks function in @keystonejs/fields

To help you get started, we’ve selected a few @keystonejs/fields examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keystonejs / keystone / packages / keystone / lib / List / index.js View on Github external
const { Relationship } = require('@keystonejs/fields');
    // Set up a fresh mutation state if we're the root mutation
    const isRootMutation = !mutationState;
    if (isRootMutation) {
      mutationState = {
        afterChangeStack: [], // post-hook stack
        queues: {}, // backlink queues
        transaction: {}, // transaction
      };
    }

    // Perform the mutation
    const { result, afterHook } = await mutation(mutationState);

    // resolve backlinks
    await Relationship.resolveBacklinks(context, mutationState);

    // Push after-hook onto the stack and resolve all if we're the root.
    const { afterChangeStack } = mutationState;
    afterChangeStack.push(afterHook);
    if (isRootMutation) {
      // TODO: Close transaction

      // Execute post-hook stack
      while (afterChangeStack.length) {
        await afterChangeStack.pop()();
      }
    }

    // Return the result of the mutation
    return result;
  }

@keystonejs/fields

KeystoneJS Field Types including Text, Password, DateTime, Integer, and more.

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Similar packages