2017-03-23 137 views
1

我有一個graphql服務器與節點/表達式和ES6運行,我想遷移到打字稿,當我想要做graphql架構我遇到一些日期問題類型。我知道graphql不包含本機日期類型,但在我的ES6實現中,我使用graphql-date來支持此限制。Graphql的日期字段類型必須是輸出類型,但得到:undefined

import { 
    GraphQLObjectType, 
    GraphQLSchema, 
    GraphQLID, 
} from 'graphql'; 

import GraphQLDate from 'graphql-date'; 

const events = new GraphQLObjectType({ 
    name: 'events', 
    description: 'This represent an Event', 
    fields:() => { 
     return { 
      id: { 
       type: GraphQLID, 
       resolve(event) { 
        return event.id; 
       } 
      }, 
      start: { 
       type: GraphQLDate, 
       resolve(event) { 
        return event.start; 
       } 
      } 
     }; 
    } 
}); 

的問題是,在我的打字稿項目運行服務器時,我得到這個消息:

Error: events.start field type must be Output Type but got: undefined. 
+1

我解決了自己的問題,GraphqlDate不會返回默認螞蟻任何的導致問題,如果我進口的進口* as ... date type well well – xzegga

+1

究竟是什麼解決方案?請分享您的代碼 –

回答

1

這裏的問題是,在打字稿import Foo from 'foo'預計模塊「富」導出module.exports.default屬性。 graphql-date模塊改爲使用覆蓋module.exports的經典Node.js模式。

爲了支持這打字稿,您可以通過混合新舊語法:

import GraphQLDate = require('graphql-date'); 
相關問題