Khalil Stemmler+ Your Authors @stemmlerjs ⚡Dev Advocate at @apollographql ⚡Author of ⚡Advanced #TypeScript, #DDDesign & architecture at ⚡Noise maker @ Jan. 23, 2020 1 min read + Your Authors

🖼️Domain-Driven GraphQL Schema Design (in 6 tweets)👇
#graphQL #eventstorming #dddesign

Most complex systems don't naturally fit within the rigid confines of CRUD. Humans tend to tame the complexity of challenging problems by understanding the problem as a series of events. Turns out, we can design our applications this way too with @eventstorming or @EventModeling.

💡1. Domain Events - Plot out all of the events that happen for the main story in your application as past-tense verbs.

For my Hackernews-like app, that looks like:

`UserCreated` => `MemberCreated` => `PostCreated` => `CommentCreated`, `CommentUpvoted`, etc.

💡2. For each Domain Event, write the Command that causes it. These are your **GraphQL mutations.**

They should be in an imperative form. If you know the name of the role/actor that performs it, you can document that as well.

💡3. For each Command/Domain Event pair, identify the Aggregate (or write model) that they belong to.

💡4. Identify the top-level Federated GraphQL fields by applying Conway's Law.

Segregate the Events, Commands, and Aggregate from each other based on the relevant self-organizing teams that play a part in the story of our application.

📖Conway's Law => 

💡5. For each Aggregate, identify all possible Views (GraphQL queries) required in order to give users enough information to perform Commands (GraphQL mutations).

💡6. Finally, create our GraphQL Schema from the discovered Commands (Mutations) and Queries.

In monoliths, you can break the schema up into separate files by `extend`-ing the Query and Mutation.

For Federated apps, you can compose schemas with the `@key` directive.

Unless you're building a CRUD app, designing a GraphQL schema isn't something that should be done in isolation.

If we're working a large-scale app, we should try to get a mix of domain experts & developers together to agree on both the business process and the resulting schema.

You can follow @stemmlerjs.


Tip: mention @threader_app on a Twitter thread with the keyword “compile” to get a link to it.

Enjoy Threader? Sign up.

Since you’re here...

... we’re asking visitors like you to make a contribution to support this independent project. In these uncertain times, access to information is vital. Threader gets 1,000,000+ visits a month and our iOS Twitter client was featured as an App of the Day by Apple. Your financial support will help two developers to keep working on this app. Everyone’s contribution, big or small, is so valuable. Support Threader by becoming premium or by donating on PayPal. Thank you.

Follow Threader