Graphql
The Graphql schema is public and thus hard to change. Because it is hard to change, naming is very important!
Read this article about building evolvable schemas
Read this article about mutation naming (Anemic Mutations)
Schema types and properties
All Graphql types should have
id: ID!createdAt: DateupdatedAt: Date
Delete for deletions, remove to ‘remove from’:deleteCar(id: ID!)removeOptionFromCar(optionId: ID!, carId: ID!)‘Number’ can be shortened toNr:chamberOfCommerceNrbranchNrphoneNrhouseNrhouseNrSuffixEmailAddress should be written out full, not shortened to emailemailAddress
Naming conventions
My-Queries and mutations that use data of the currently logged in user should use theMyprefix. I.E.MyDealretrieves the Deal of the currenly logged in user.updateMyUserProfileupdates the profile of the currently logged in user.- Retrieving - Retrieving data happens by type. I.E. getting an
Articlehappens with the queryArticle()NOT getArticle(). This follows graphcool’s/Prisma’s query naming convention. - Retrieving multiple - Retrieving multiple entities uses
all. I.E.allArticles()
PubSub Topics
Use lower-kebab-case naming for PubSub topics, as shown in the GCP documentation.
Code naming
Don’t make life hard for your fellow developers, read this article about naming psychology.
- Names should be descriptive:
const userIdPerfectly understandable. ‘const uId’ is NOT, and it is horrible. - Don’t be TOO descriptive.
sign(contract: Contract)this is descriptive enough. ‘signContract(contract)’ is redundant. - Scope/context aware naming: If the scope of your variable is tiny, it is ok to have a short name for your variable:
contracts.filter(c => !!c)C is obviously contract in this example.
validateEmailAddress(email: string)There is no ambiguity inemailin this context
Phone.emailAddress- phone.email could mean an actual email message here.