This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Feature Flags Graphql API
About the Database
Relationship: I choose a design that allows an
N-to-N
relationship betweenfeature_flag
anduser_account
entities. The idea is to link both data in a third entity calleduser_feature_flag
where only one value is accepted for each combination ofUser
andFeature Flag
domains.Feature Flag entity:
The
feature_flag
entity is composed of a simple unique property calledfeature_flag_key
responsible for the description of a feature flag, followed by an autoincrementid
andcreated_at
properties.User Feature Flag entity:
The
user_feature_flag
entity is composed ofuser_id
andfeature_flag_id
foreign keys that references touser_account
andfeature_flag
entities, respectively. The propertyfeature_flag_value
is atext
property responsible for keeping the feature flag data.About Graphql Queries and Mutations
I created only one mutation
setUsersFeatureFlagMutation
which is able totarget one or more users with a specific feature flag
and alsochange the value of a feature flag for a specific user
.The
User
query is responsible for loading theuser_account
data groupinguser_feature_flag
list inside it self by using aUserFeatureFlag
resolver, which counts with adataloader
implementation to avoid excessive and unnecessary database requests for each user node.Data Layer
To maintain the Data logic handlers abstracted from resolvers, I choose to create a
Dasource
composition where each exposed domain has an exclusive object with its own logic.About tests
That was my first project with fastify and slonik (and I have no clue of how to inject a Postgre connection inside of it), so to keep it simple I just added unit tests on dto's adapter functions. But it would be a great evolution to this code to add integration tests.
To Watch My Loom Video:
Click Here!