2017-01-27 34 views
2

我正在使用apollo-express graphql服務器。我試圖整合模塊'graphql-type-json',但是當我遵循this description關於如何集成時,我嘗試了很多東西,但似乎這個類型沒有被正確地傳遞給解析器 - 但我已經命中我的調試中有一堵牆,可以使用一點幫助。這是我正在做的事情的總結。Apollo Graphql自定義標量JSON - 抱怨「TypeError:type.getFields不是函數」

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, 
}); 

不知道,如果是相關的,但也有與我的新公共管理的幾個問題:

[email protected] 

UNMET PEER DEPENDENCY [email protected] invalid 

├─┬ [email protected] 

│ ├── UNMET PEER DEPENDENCY [email protected]^0.5.0 || ^0.6.0 


npm ERR! peer dep missing: [email protected]^0.6.1 || ^0.7.0, required by [email protected] 

npm ERR! peer dep missing: [email protected]^0.5.0, required by [email protected] 

npm ERR! extraneous: [email protected] /home/apollo/node_modules/casual 

npm ERR! extraneous: [email protected] /home/apollo/node_modules/mongoose 

npm ERR! extraneous: [email protected] /home/apollo/node_modules/mysql-events 

npm ERR! peer dep missing: [email protected]^0.5.0 || ^0.6.0, required by [email protected] 
+0

「(節點:5338)UnhandledPromiseRejectionWarning:未處理的承諾拒絕(拒絕ID:1):TypeError:type.getFields不是函數」是確切的警告我得到 – RobotBox2000

+0

我建議升級到最新版本的'graphql-tools'和'graphql',並使用最新的'graphql-server-express',它是'apollo-server'的新名稱。這可能是依賴關係的一些奇怪的交互。 – stubailo

回答

1

我解決了解析器

JSON: { 

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

定製標JSON這樣,它的工作罰款我。我認爲它會幫助你