Feature based GraphQL Modules at scale
This way, each module can declare only the part of the schema that it contributes, and the complete schema is a representation of all merged type definitions.
Module can also depend, import and extend and customize the contents on other modules (for example, User
module, comes with Auth
inside it)
The result of course, will be the same, because we are merging the schema into a single one, but the codebase will be much more organized and each module will have its own logic.
Reusability of backend modules
So now that we understood the power of feature-based implementation, it’s easier to grasp the idea behind code reusability.
If we could implement the schema and the core of Auth and User module as “plug-and-play” — we will be able later to import it in other projects, with very minor changes (using configuration, dependency injection, or module composition).
How could we reuse complete modules that hold part of a schema?
For example, let’s take a User
type.
Most of User
type schemas will contain id
, email
and username
fields. The Mutation type will have login
and the Query
will have user
field to query for a specific user.
We can re-use this type declaration.
The actual implementation might differ between apps, according to the authentication provider, database and so on, but we can still implement the business logic in a simple resolver, and use dependency injector and ask the app that’s using the module to provide the actual authentication function (of course, with a complete TypeScript interface so we’ll know that we need to provide it ;) ).
Let’s take it one step further. If we would like to add a profile picture to a user, we can add a new module named UserProfile
and re-declare the User
and Mutation
types again:
This way, GraphQL Modules will merge the fields from this User
type into the complete User
type, and this module will only extend the User
type and Mutation
type with the required actions.
So let’s say that we have the schema — how can we make this module generic and re-use it?
This is how you declare this module:
We declare a config object, and the app will provide it for us, so we can later replace it with a different logic for uploading.
Scaling the codebase
Now that we broke our app into individual modules, once our codebase grows, we can scale each module individually.
What do I mean by scaling a codebase?
Let’s say we start to have code parts we want to share between different modules.
The current way of doing it in the existing GraphQL world is through a GraphQL context.
This approach has proven itself to work, but at some point it becomes a big hassle to maintain, because GraphQL context is an object, which any part of the app can modify, edit and extend, and it can become really big pretty quickly.
GraphQL modules let each module extend and inject fields to the `context` object, but this is something that you should use with caution, because I recommend the `context` to contain the actual `context` — which contains data such as global configuration, environment, the current user and so on.
GraphQL modules only adds one field under the context
, called injector
which is the bridge that lets you access your GraphQLApp and the application Injector, and it lets you fetch your module’s config and providers.
Modules can be a simple directory in a project or in a monorepo, or it could be a published NPM module — you have the power to choose how to manage your codebase according to your needs and preferences.
Dependency Injection
GraphQL Modules’ dependency injection is inspired by .NET and Java’s dependency injection which has proven itself to work pretty well over the years. With that being said, there were some issues with .NET and Java’s APIs, which we’ve tried to list and go through. We ran into some pretty interesting conclusions.
We’ve learn that it’s not something that should be forced. Dependency injection makes sense in some specific use cases and you should need to use it only when it’s necessary and when it helps you move faster. So this concept should come more and more in handy as we scale up, we can simplify things, maintain our code with ease and manage our teams’ contributions!
Having GraphQL Modules deployed across all of our Enterprise customers while also being used on our smaller applications, lead us to believe that we’ve found the optimal point of where you should use the concept of dependency injection, and when not.
We’ve also came with the optimal API for dependency injection. It’s extremely easy to understand, and use.
After a long research of the existing dependency injection solutions for JavaScript, we’ve decided to implement a simple Injector, that supports the needs of GraphQL-Modules ecosystem, and support circular dependencies and more.
We’ve simplified the Dependency Injection API and exposed to you only the important parts, that we believe that are necessary for a GraphQL server development.
Authentication
Testing and mocking
On our Enterprise applications, when we started using dependency injection, we no longer had to manage instances and bridge them together.
We gained an abstraction that allowed us to test things easier and mock all http requests.
Yes, mocking. DI really shines here.
Thanks to mocking we can simulate many scenarios and check the backend against them.
And when your codebase grows, you need to start thinking about managing dependencies between modules and how to avoid things like circular dependencies — unless you use DI which solves that problem for you.
With the power of dependency injection, you can easily create a loose connection between modules, and base this connection on a token and on a TypeScript interface.
It also means that testing is much easier — you can take your class/function and test it as an independent unit, and mock its dependencies easily.
Summary
We see GraphQL Modules as the framework that finally being built from the ground up on the new and exciting capabilities of GraphQL and Apollo, while combining it in the right way with good old software best practices for scale like modularizations, strong typings and dependency injection.
相關推薦
Feature based GraphQL Modules at scale
This way, each module can declare only the part of the schema that it contributes, and the complete schema is a representation of all merged type definitio
《The challenge of realistic music generation: modelling raw audio at scale》論文閱讀筆記
mes esc color del strac argmax bst repr 幫助 The challenge of realistic music generation: modelling raw audio at scale 作者:Deep mind三位大神
graphql-modules 企業級別的graphql server 工具
graphql-modules 是一個新開源的graphql 工具,是基於apollo server 2.0 的擴充套件庫,該團隊 認為開發應該是模組化的。 幾張來自官方團隊的架構圖可以參考,方便比較 apollo server 的開發模型 從上圖看出,一般的graphql 簡單功能我們都是可
Personalization at Scale With Machine Learning: The Xero Story
When Nigel Piper, Executive General Manager, first joined Xero, the company only had 100,000 subscribers. In over ten years that number has risen to over 1
The new frontier: Agile automation at scale
Large-scale automation of business processes requires a new development approach. Across sectors, business processes are undergoing the most profound trans
based command center at NHS teaching hospital | AITopics
GE Healthcare has been tapped to build a centralized healthcare "command center" at the Bradford Royal Infirmary, an NHS teaching hospital in the U.K., to
Serverless Streaming At Scale with Cosmos DB
Serverless Streaming At Scale with Cosmos DBAbout 100% serverless Kappa Architecture implementation, singletons, scaling, and multi-threadingI’m doing a lo
tech businesses are beginning to use artificial intelligence at scale | AITopics
LIE DETECTORS ARE not widely used in business, but Ping An, a Chinese insurance company, thinks it can spot dishonesty. The company lets customers apply fo
Managing Software Dependency at Scale
Introduction At LinkedIn, we have more than 10,000 separate software codebases, referred to as multiproducts, which represent individual software product
Tracking User Behavior At Scale with Streaming Reactive Big Data Systems
Tracking User Behavior At Scale with Streaming Reactive Big Data SystemsBehavioral Analytics through Big Data Applications can be used to gain insights, an
First Business Models at Scale | Machine Learning Blog
Earlier this week, MIT, in collaboration with Boston Consulting Group, released their second global study looking at AI adoption in industry. A top fin
High Quality Video Encoding at Scale
High Quality Video Encoding at ScaleAt Netflix we receive high quality sources for our movies and TV shows and encode them to the best video streams possib
Learning at Scale & The End of “If -Then” Logic.
Learning at Scale & The End of “If -Then” Logic.In 2001, a group of Physicists were awarded the Nobel prize in Physics for creating an experiment that
Server Fleet Managemement at Scale
Amazon Web Services (AWS) customers who own a fleet of servers are sometimes unsure of how to best automate their fleet management for opera
Amazon Machine Learning – Make Data-Driven Decisions at Scale
Today, it is relatively straightforward and inexpensive to observe and collect vast amounts of operational data about a system, product, or proces
Launch – Hello Amazon Macie: Automatically Discover, Classify, and Secure Content at Scale
When Jeff and I heard about this service, we both were curious on the meaning of the name Macie. Of course, Jeff being a great researcher looked u
Accelerating Precision Medicine at Scale
This post courtesy of Aaron Friedman, Healthcare and Life Sciences Partner Solutions Architect, AWS and Angel Pizarro, Genomics and Life Sciences
Quantum computing at scale: Scientists achieve compact, sensitive qubit readout
The research, conducted within the Simmons group at the Centre of Excellence for Quantum Computation and Communication Technology (CQC2T) with PhD student
Scrum At Scale® 指南-切實可行的規模化擴充套件敏捷
Scrum At Scale® 指南版權所有© 2006-2018 Jeff Sutherland 及 Scrum Inc.[email protected]是Scrum Inc.的註冊商標。本指南基於署名-相同方式共享許可協議4.0釋出。(CC BY-SA 4.0)簡體中文版原創翻譯團隊:申健 J
RDMA over Commodity Ethernet at Scale (I)
Abstract 在過去一年半的時間,我們已經使用RoCEv2來支援一些微軟高可靠性、延遲敏感的服務。本篇論文講述了在此過程中遇到的挑戰以及解決方案。為了把RoCEv2擴充套件到VLAN之外,我們設計了一個基於DSCP的優先順序流量控制機制(PFC)來確保大規模部署。我們已