I like the Universal Relay Boilerplate - in general I can tell they were very thoughtful about how they put this whole thing together, unlike most boilerplates for which folder organization and so on seems to be an intended afterthought (I guess because you won't do anything important at first, or something)... but not URB. Or at least we are picky about the same things.
Why do the same annoying thing...
...except for one thing: I don't get why they do this.
// 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
}
}
...two times in close proximity with no explanation?
Here is the "Type" which is actually a bit different than the original by virtue of an alias.
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,
},
} );
They intend it obviously
This is the most dramatic example of difference between model
and type
I could find in the boilerplate; the others are identical. I was actually a bit annoyed to find that no other guide recommends or even mentions doing a model.js
but rather starts from a type.js
.
I could understand if
- Some types need to differ from models for security, performance, aesthetic, design, etc
- Some types span models deliberately
- Some types encapsulate models for design reasons
But they do it everywhere which leads me to think I am missing something important here.