Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/Felipe Renato #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

felipeourenato
Copy link

@felipeourenato felipeourenato commented Sep 5, 2022

Feature Flags Graphql API

About the Database

Relationship: I choose a design that allows an N-to-N relationship between feature_flag and user_account entities. The idea is to link both data in a third entity called user_feature_flag where only one value is accepted for each combination of User and Feature Flag domains.

Feature Flag entity:

The feature_flag entity is composed of a simple unique property called feature_flag_key responsible for the description of a feature flag, followed by an autoincrement id and created_at properties.

User Feature Flag entity:

The user_feature_flag entity is composed of user_id and feature_flag_id foreign keys that references to user_account and feature_flag entities, respectively. The property feature_flag_value is a text property responsible for keeping the feature flag data.

About Graphql Queries and Mutations

  • I created only one mutation setUsersFeatureFlagMutation which is able to target one or more users with a specific feature flag and also change the value of a feature flag for a specific user.

  • The User query is responsible for loading the user_account data grouping user_feature_flag list inside it self by using a UserFeatureFlag resolver, which counts with a dataloader 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!

@felipeourenato felipeourenato marked this pull request as draft September 5, 2022 21:45
@felipeourenato felipeourenato changed the title Backend/felipe renato Backend/Felipe Renato Sep 5, 2022
@felipeourenato felipeourenato marked this pull request as ready for review September 6, 2022 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant