Git Product home page Git Product logo

Comments (3)

eric-burel avatar eric-burel commented on June 26, 2024

Current approach defining a schema extension from the extender, and importing it in the extended schema:

/**
 * TODO: currently we have to import this in the "Response" model
 * In the future this should be instead tied to the "NormalizedResponse" model
 * To avoid a dependency Response->NormalizedResponse (we only want NormalizedResponse->Response)
 * @see https://github.com/VulcanJS/vulcan-npm/issues/133
 */
export const responseSchemaExtension = {
  /**
   * TODO: this creates a strong dependency to the admin area
   * And this field is only used in admin display
   *
   * Possible solutions:
   * - put the NormalizedResponse model and Response model into a shared folder
   * - find a way to extend the Response model based on NormalizedResponse
   *
   * + we could create a relation resolver for this in Vulcan for those
   * kind of "virtual" relations (the foreign key is in the related model instead of the current model)
   *
   * @see https://github.com/VulcanJS/vulcan-npm/issues/133
   *
   */
  normalizedResponse: {
    type: Object,
    typeName: "JSON",
    blackbox: true,
    optional: true,
    canRead: ["owners"],
    resolveAs: {
      fieldName: "normalizedResponse",
      typeName: "JSON",
      // TODO: use a relation instead
      resolver: async (response: ResponseDocument) => {
        return await NormalizedResponseConnector.findOne({
          responseId: response._id,
        });
      },
    },
  },
};

from vulcan-npm.

eric-burel avatar eric-burel commented on June 26, 2024

Better: "belongsToOne" and "belongsToMany" as new relation types

from vulcan-npm.

eric-burel avatar eric-burel commented on June 26, 2024

Done see https://vulcan-docs.vercel.app/docs/vulcan-fire/customFieldResolvers#method-2---assess-if-a-reversed-relation-is-enough-for-you-advanced

Field is named "reversedRelation" (because there can already be a relation) and types are "hasOneReversed" and "hasManyReversed". This might be slightly complex to understand, but the way it works become intuitive if you have a separate admin area for instance.

from vulcan-npm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.