node.js 743 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. const {
  3. nodeDefinitions,
  4. fromGlobalId
  5. } = require('graphql-relay');
  6. // At this point, videoType is not yet defined because of the require loop.
  7. const { getObjectById } = require('./data');
  8. const { nodeInterface, nodeField } = nodeDefinitions(
  9. // Load an object from its id.
  10. globalId => {
  11. const { type, id } = fromGlobalId(globalId);
  12. return getObjectById(type.toLowerCase(), id);
  13. },
  14. // Returns the object type.
  15. object => {
  16. // But this import is done after the whole loading require loop has completed.
  17. const { videoType } = require('../index');
  18. if (object.title) {
  19. return videoType;
  20. }
  21. return null;
  22. }
  23. );
  24. exports.nodeInterface = nodeInterface;
  25. exports.nodeField = nodeField;