首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apollo Graphql Custom Scalar JSON -抱怨"TypeError: type.getFields不是一个函数“

Apollo Graphql Custom Scalar JSON -抱怨"TypeError: type.getFields不是一个函数“
EN

Stack Overflow用户
提问于 2017-01-28 04:39:57
回答 1查看 1.3K关注 0票数 2

我在一个apollo-express graphql服务器上工作。我试图集成“graphql- type -json”模块,但当我跟随this description学习如何集成时,我尝试了很多方法,但似乎类型没有正确地传递给解析器--但我在调试过程中遇到了困难,需要一点帮助。这是我正在做的事情的摘要。

代码语言:javascript
复制
import { makeExecutableSchema } from 'graphql-tools';
const GraphQLJSON = require('graphql-type-json');
//Have also tried import GraphQLJSON from 'graphql-type-json';

const schema = `
scalar JSON

type Device {
  deviceconfig: JSON
}

type Query {
  foo: Foo
}
`;

const resolveFunctions = {
   JSON: GraphQLJSON,
   //JSON: {return GraphQLJSON} stops error but other issues come up...
   Query: ...
 };

const jsSchema = makeExecutableSchema({
typeDefs: schema,
resolvers: resolveFunctions,
resolverValidationOptions: {
  requireResolversForNonScalar: false,
},
allowUndefinedInResolve: true,
printErrors: true,
});

不确定它是否相关,但我的npm有几个问题:

代码语言:javascript
复制
graphql-type-json@0.1.4

UNMET PEER DEPENDENCY graphql@0.8.2 invalid

├─┬ graphql-tools@0.4.2

│ ├── UNMET PEER DEPENDENCY graphql@^0.5.0 || ^0.6.0


npm ERR! peer dep missing: graphql@^0.6.1 || ^0.7.0, required by apollo-server@0.3.3

npm ERR! peer dep missing: graphql@^0.5.0, required by graphql-tools@0.4.2

npm ERR! extraneous: casual@1.5.8 /home/apollo/node_modules/casual

npm ERR! extraneous: mongoose@4.6.6 /home/apollo/node_modules/mongoose

npm ERR! extraneous: mysql-events@0.0.8 /home/apollo/node_modules/mysql-events

npm ERR! peer dep missing: graphql@^0.5.0 || ^0.6.0, required by express-widgetizer@0.5.11
EN

回答 1

Stack Overflow用户

发布于 2017-06-28 13:44:51

我在解析器中像这样解析了自定义标量JSON

代码语言:javascript
复制
 JSON: {

    __serialize(value) {
        return GraphQLJSON.parseValue(value);
    } }

对我来说效果很好。我想这会对你有帮助的

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41902647

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档