1

我正在尝试fromGlobalId使用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;
};

但我在控制台中收到此错误:

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.

我已经调查过了graphql-relay,它显然是出口fromGlobalId在此处输入图像描述

Ps:我正在使用节点 13.6.0 以便使用 es6 导入语法..

提前致谢,我们将不胜感激。

4

0 回答 0