1

I am tring to use fromGlobalId from graphql-relay:

import { nodeDefinitions, fromGlobalId } from 'graphql-relay';
import db from './database/index.js';

const idResolver = (globalId, context) => {
  const { type, id } = fromGlobalId(globalId);
  if (type === 'User') {
    return db.getUser({ id }, context);
  }
  return null;
};

But I get this error in my console:

file:///Users/tomerlevi/Github/bali/graphql/node.js:5
import { fromGlobalId, nodeDefinitions } from 'graphql-relay';
         ^^^^^^^^^^^^
SyntaxError: The requested module 'graphql-relay' does not provide an export named 'fromGlobalId'
    at ModuleJob._instantiate (internal/modules/esm/module_job.js:92:21)
    at ModuleJob.run (internal/modules/esm/module_job.js:107:20)
    at Loader.import (internal/modules/esm/loader.js:141:24)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! serverless-graphql@0.0.0 update-schema: `babel-node foundation/graphql/updateSchema.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the serverless-graphql@0.0.0 update-schema script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

I have looked into graphql-relay and it clearly exports fromGlobalId: enter image description here

P.s: I am using node 13.6.0 in order to use es6 import syntax..

THANKS IN ADVANCE, ANY HELP WILL BE APPRECIATED.

Community
  • 1
  • 1
Tomer
  • 1,521
  • 1
  • 15
  • 26
  • Those are Typescript types. When you use transpile your code with Typescript or Babel, the transpiler can make your `import` work even if the module you're importing doesn't use named exports (i.e. it uses `module.exports` instead of `export cost`). But if you're using vanilla node, the `module.exports` syntax won't be compatible with the new way of doing imports. See the linked dupe for additional details and a workaround. – Daniel Rearden Jan 12 '20 at 21:55
  • Thanks @Rearden will take a look – Tomer Jan 12 '20 at 21:57

0 Answers0