我喜欢 Universal Relay Boilerplate - 总的来说,我可以说他们对如何将整个事情组合在一起非常周到,不像大多数样板,文件夹组织等似乎是事后的想法(我猜是因为你不会这样做一开始任何重要的事情,或者其他什么)......但不是URB。或者至少我们对同样的事情很挑剔。
为什么要做同样烦人的事情...
...除了一件事:我不明白他们为什么这样做。
// Class used by GraphQL Server
export default class User
{
constructor( fields )
{
this.id = fields.id
this.User_AccountName = fields.User_AccountName
this.User_AccountPassword = fields.User_AccountPassword
this.User_DisplayName = fields.User_DisplayName
this.User_ProfilePhoto = fields.User_ProfilePhoto
this.User_Email = fields.User_Email
this.User_PhoneNumberMobile = fields.User_PhoneNumberMobile
this.User_Locale = fields.User_Locale
this.UserToken2 = fields.UserToken2
}
}
......两次近距离没有解释?
这是“类型”,由于别名,它实际上与原始有点不同。
export default new GraphQLObjectType( {
name: 'Viewer',
interfaces: [NodeInterface],
isTypeOf: object => object instanceof User,
fields: {
id: globalIdField('Viewer'),
User_IsAnonymous: { type: GraphQLBoolean, resolve: (obj) => obj.id.equals( Uuid_0 ) },
User_AccountName: { type: GraphQLString, resolve: (obj) => obj.User_AccountName },
User_DisplayName: { type: GraphQLString, resolve: (obj) => obj.User_DisplayName },
User_ProfilePhoto: { type: GraphQLString, resolve: (obj) => obj.User_ProfilePhoto },
User_Email: { type: GraphQLString, resolve: (obj) => obj.User_Email },
User_PhoneNumberMobile: { type: GraphQLString, resolve: (obj) => obj.User_PhoneNumberMobile },
User_Locale: { type: GraphQLString, resolve: (obj) => obj.User_Locale },
UserToken2: { type: GraphQLString, resolve: (obj) => obj.UserToken2 },
..._ViewerFields,
},
} );
他们显然是故意的
这之间的差异最显着的例子model和type我可以在样板找到; 其他是相同的。发现没有其他指南推荐甚至提到做 amodel.js而是从type.js.
我能理解如果
- 某些类型需要在安全性、性能、美学、设计等方面与模型不同
- 某些类型故意跨模型
- 某些类型出于设计原因封装模型
但是他们到处都这样做,这让我觉得我在这里遗漏了一些重要的东西。
