Skip to content

iudukala/graphql_task

Repository files navigation

requirements specified

All code written should follow domain driven design

domain design pricinciples outlined by Khalil Stemmler in https://khalilstemmler.com and Martin Fowler in https://martinfowler.com have been followed to the best of my ability.

When the fruit is created, updated, or deleted; a domain event should be emitted. The event has to guarantee at least once delivery.

each mutation event adds an entry to the transaction outbox, a separate collection in persistence. handlers are registerd through the domain events manager for event consumption that run at regular intervals. guaranteeing at least once delievery however, requires the use of transactions in mongodb, which is only available if the mongodb instance is a member of a replica set. transaction logic is implemented however and when connected to the mongodb atlast database instance (primary DB_URI in .env, and the default database outside testing), atomic transactions are performed to ensure atleast once delivery of the event to the transaction outbox

The description of a fruit can't be beyond 30 letters:

ensured by using a value object in the domain entity Fruit

The name of a fruit should be unique:

ensured through a check performed in a domain service before being committed to persistence

The creation of a fruit should be done through a factory

implemented inside Fruit class

The fruit should be retrieved through a Repository

a repository has been implemented (FruitRepo) that handles persistence layer mutations

The fruit should be converted from a database object to a domain object and viceversa through mappers:

performed through static functions made available through a class

Use Mongoose for your ORM

mongoose used

Use Jest for your testing

jest used. (does not have esm support) also added tests to github actions

Use https://nexusjs.org to automatically generate your GraphQL schemas

nexusJS used

issues faced

  • found an issue where a const enum wasn't being accepted by the omit utility function in typescript. worked as expected when using pick<> to select the fields required but didn't when trying to use it to exclude the fields to extract the required ones. this turned out to be an issue with enums. const enums are static enough to be inlined at compile time so there should be no reason why they'd be insufficient for type construction. switched to using const asserted object microsoft/TypeScript#40944

  • insufficient esm support from jest. got esm modules to load with code transforms from ts-jest plugin but jest still fails when attempting to access import.meta global "error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'" when tsconfig has 'module' set to 'es2020'. not an issue with tsconfig visibility to jest since it respects other flags set in it.

  • nexus js does not seem to support esm. even with all esm related compiler flags, the autogenerated artifacts use commonJS imports, forcing manual modification of import statements each time a modification is made to the graphql schema. automatic generation needs to be turned off afterwards to avoid nexusjs overwriting the modifications. (also, transpile-only flag)

  • nexus does not have great documentation

  • depending on when you encounter a bug while working with nexusJS, the autogenerated schema may not be recompiled after the last compilation. this means that any changes that require fetching data from the autogenerated files (like query/mutation arguments/types) may not be available within the resolver until the resolver can compile again, allowing the autogenerated artifacts to be compiled again.

improvements

  • better immutability

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages