Skip to content

Commit

Permalink
Fixed typescript enums and restructured the project. (#870)
Browse files Browse the repository at this point in the history
* updated INSTALLATION.md

* refactored and reorganized files/folders for better structure

* updated test coverage included directories and remove unused package copyfiles

* added @types/cors and fixed lint error
  • Loading branch information
xoldd authored Jan 24, 2023
1 parent 4ae411a commit 650f038
Show file tree
Hide file tree
Showing 370 changed files with 1,274 additions and 1,547 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
build
coverage
node_modules
src/generated
src/types
3 changes: 1 addition & 2 deletions .github/workflows/check-jsdocs-comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def get_directories():
# list of dir to look in repo for files
directories = [
directory,
os.path.expanduser(os.path.join(directory, 'lib')),
os.path.expanduser(os.path.join(directory, 'src')),
os.path.expanduser(os.path.join(directory, 'test'))
os.path.expanduser(os.path.join(directory, 'tests'))
]
return directories

Expand Down
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules
nodemon.json
.idea
.env
images
Expand All @@ -9,12 +8,9 @@ images
yarn.lock
pnpm-lock.yaml

# We don't want to have code coverage data stored in the repo as it is dynamic
# These files/folders are dynamic and should not be pushed to the repo.
# They should be generated on the fly whenever they're needed.
coverage

# We don't want to push emitted production build of talawa-api to github.
# Since it will only be needed in CI/CD and production environment it
# should be generated on the fly at that time.
build

serviceAccountKey.json
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
build
coverage
node_modules
src/generated
src/types
85 changes: 47 additions & 38 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Contributing to Talawa API
Thank you for your interest in contributing to Talawa API. Regardless of the size of the contribution you make, all contributions are welcome and are appreciated.

Thank you for your interest in contributing to Talawa API. Regardless of the size of the contribution you make, all contributions are welcome and are appreciated.

If you are new to contributing to open source, please read the Open Source Guides on [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/).

## Table of Contents

- [Code of Conduct](#code-of-conduct)
- [Ways to Contribute](#ways-to-contribute)
- [Our Development Process](#our-development-process)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Branching Strategy](#branching-strategy)
- [Contributing Code](#contributing-code)
- Internships
- [GSoC](#gsoc)
- [Community](#community)
- [Code of Conduct](#code-of-conduct)
- [Ways to Contribute](#ways-to-contribute)
- [Our Development Process](#our-development-process)
- [Issues](#issues)
- [Pull Requests](#pull-requests)
- [Branching Strategy](#branching-strategy)
- [Contributing Code](#contributing-code)
- Internships
- [GSoC](#gsoc)
- [Community](#community)

## Code of Conduct

A safe environment is required for everyone to contribute. Read our [Code of Conduct Guide](CODE_OF_CONDUCT.md) to understand what this means. Let us know immediately if you have unacceptable experiences in this area.

No one should fear voicing their opinion. Respones must be respectful.
Expand All @@ -38,12 +40,15 @@ If you are ready to start contributing code right away, get ready!
Welcome aboard!

### Our Development Process
We utilize GitHub issues and pull requests to keep track of issues and contributions from the community.

#### Issues
We utilize GitHub issues and pull requests to keep track of issues and contributions from the community.

#### Issues

Make sure you are following [issue report guidelines](issue-guidelines.md) available here before creating any new issues on Talawa API project.

#### Pull Requests

[Pull Request guidelines](PR-guidelines.md) is best resource to follow to start working on open issues.

#### Branching Strategy
Expand All @@ -55,29 +60,31 @@ For Talawa API, we had employed the following branching strategy to simplify the
- `master`: Where the stable production ready code lies

### Contributing Code

Code contributions to Talawa come in the form of pull requests. These are done by forking the repo and making changes locally.

Make sure you have read the [Documentation for Setting up the Project](INSTALLATION.md)
Make sure you have read the [Documentation for Setting up the Project](./INSTALLATION.md)

The process of proposing a change to Talawa API can be summarized as:

1. Fork the Talawa API repository and branch off `develop`.
1. The repository can be cloned locally using `git clone <forked repo url>`.
1. Make the desired changes to the Talawa API source.
1. Run the app and test your changes.
1. If you've added code, then test suites must be added.
1. **_General_:**
1. If you've added code, then test suites must be added.
1. **_General_:**
1. We need to get to 100% test coverage for the app. We periodically increase the desired test coverage for our pull requests to meet this goal.
1. Pull requests that don't meet the minimum test coverage levels will not be accepted. This may mean that you will have to create tests for code you did not write. You can decide which part of the code base needs additional tests if this happens to you.
1. **_Testing_:**
1. Test using these commands (All tests):
```
npm run test
genhtml coverage/lcov.info -o coverage
```
```
1. Test using these commands (Single test):
```
npm run test -- -t <Name_of_Test>
```
```
1. Here are some useful testing resources:
1. Documentation:
1. [Jest testing documentation](https://jestjs.io/docs/expect)
Expand All @@ -87,39 +94,41 @@ The process of proposing a change to Talawa API can be summarized as:
1. [Jest Crash Course](https://www.youtube.com/watch?v=7r4xVDI2vho)
1. [Testing NodeJS applications with JEST](https://www.youtube.com/watch?v=8gHEv5iNRKk)
1. **_Test Code Coverage_:**
1. _General Information_
1. The current code coverage of the repo is: [![codecov](https://codecov.io/gh/PalisadoesFoundation/talawa-api/branch/develop/graph/badge.svg?token=CECBQTAOKM)](https://codecov.io/gh/PalisadoesFoundation/talawa-api)
1. You can determine the percentage test coverage of your code by running these two commands in sequence:
```
npm install
npm run test
genhtml coverage/lcov.info -o coverage
```
1. The coverage rate will be visible on the penultimate line of the `genhtml` command's output.
1. The `genhtml` command is part of the linux `lcov` package. Similar packages can be found for Windows and MacOS.
1. The currently acceptable coverage rate can be found in the [GitHub Pull Request file](.github/workflows/pull-request.yml). Search for the value below the line containing `min_coverage`.
1. _Creating your code coverage account_
1. You can also see your code coverage online for your fork of the repo. This is provided by `codecov.io`
1. Go to this link: `https://app.codecov.io/gh/XXXX/YYYY` where XXXX is your GitHub account username and YYYY is the name of the repository
1. Login to `codecov.io` using your GitHub account, and add your **repo** and **branches** to the `codecov.io` dashboard.
1. Remember to add the `Repository Upload Token` for your forked repo. This can be found under `Settings` of your `codecov.io` account.
1. Use the value of this token to create a secret named CODE_COV for your forked repo.
1. You will see your code coverage reports with every push to your repo after following these steps
1. _General Information_
1. The current code coverage of the repo is: [![codecov](https://codecov.io/gh/PalisadoesFoundation/talawa-api/branch/develop/graph/badge.svg?token=CECBQTAOKM)](https://codecov.io/gh/PalisadoesFoundation/talawa-api)
1. You can determine the percentage test coverage of your code by running these two commands in sequence:
```
npm install
npm run test
genhtml coverage/lcov.info -o coverage
```
1. The coverage rate will be visible on the penultimate line of the `genhtml` command's output.
1. The `genhtml` command is part of the linux `lcov` package. Similar packages can be found for Windows and MacOS.
1. The currently acceptable coverage rate can be found in the [GitHub Pull Request file](.github/workflows/pull-request.yml). Search for the value below the line containing `min_coverage`.
1. _Creating your code coverage account_
1. You can also see your code coverage online for your fork of the repo. This is provided by `codecov.io`
1. Go to this link: `https://app.codecov.io/gh/XXXX/YYYY` where XXXX is your GitHub account username and YYYY is the name of the repository
1. Login to `codecov.io` using your GitHub account, and add your **repo** and **branches** to the `codecov.io` dashboard.
1. Remember to add the `Repository Upload Token` for your forked repo. This can be found under `Settings` of your `codecov.io` account.
1. Use the value of this token to create a secret named CODE_COV for your forked repo.
1. You will see your code coverage reports with every push to your repo after following these steps
1. After making changes you can add them to git locally using `git add <file_name>`(to add changes only in a particular file) or `git add .` (to add all changes).
1. After adding the changes you need to commit them using `git commit -m '<commit message>'`(look at the commit guidelines below for commit messages).
1. Once you have successfully commited your changes, you need to push the changes to the forked repo on github using: `git push origin <branch_name>`.(Here branch name must be name of the branch you want to push the changes to.)
1. Now create a pull request to the Talawa repository from your forked repo. Open an issue regarding the same and link your PR to it.
1. Ensure the test suite passes, either locally or on CI once a PR has been created.
1. Ensure the test suite passes, either locally or on CI once a PR has been created.
1. Review and address comments on your pull request if requested.
## Internships
We have internship partnerships with a number of organizations. See below for more details.
### GSoC
If you are participating in the Summer of Code, please read more about us and our processes [here](https://docs.talawa.io/docs/internships/gsoc/gsoc-introduction)
## Community
There are many ways to communicate with the community.
1. The Palisadoes Foundation has a Slack channel where members can assist with support and clarification. Visit the [Talawa GitHub repository home page](https://github.com/PalisadoesFoundation/talawa) for the link to join our slack channel.
Expand Down
24 changes: 0 additions & 24 deletions __tests__/resolvers/DirectChat/index.spec.ts

This file was deleted.

22 changes: 0 additions & 22 deletions __tests__/resolvers/DirectChatMessage/index.spec.ts

This file was deleted.

24 changes: 0 additions & 24 deletions __tests__/resolvers/GroupChat/index.spec.ts

This file was deleted.

26 changes: 0 additions & 26 deletions __tests__/resolvers/Organization/index.spec.ts

This file was deleted.

80 changes: 80 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: ["./src/typeDefs/**/*.ts", "scalar Upload"],

generates: {
"./src/types/generatedGraphQLTypes.ts": {
plugins: ["typescript", "typescript-resolvers"],

config: {
// Generates graphQL enums as typescript union types.
enumsAsTypes: true,

// Makes the info argument passed to the resolver functions optional.
optionalInfoArgument: true,

// Makes the resolver function callable.
makeResolverTypeCallable: true,

// Adds suffix "Model" to the end of generated database model types.
mapperTypeSuffix: "Model",

// Mappers lets us provide database model types to be used in generated typescript types instead of graphql types. This
// is because what we retrieve from the database and what we choose to return from a graphql server could be completely
// different fields. This also helps in seperating out resolver logic for nested relation fields into their own resolvers
// instead of resolving them in the root resolver itself.
mappers: {
MessageChat: "../models/MessageChat#Interface_MessageChat",

Comment: "../models/Comment#Interface_Comment",

DirectChat: "../models/DirectChat#Interface_DirectChat",

DirectChatMessage:
"../models/DirectChatMessage#Interface_DirectChatMessage",

Donation: "../models/Donation#Interface_Donation",

Event: "../models/Event#Interface_Event",

// EventProject: '../models/EventProject#Interface_EventProject'

// File: '../models/File#Interface_File',

Group: "../models/Group#Interface_Group",

GroupChat: "../models/GroupChat#Interface_GroupChat",

GroupChatMessage:
"../models/GroupChatMessage#Interface_GroupChatMessage",

// ImageHash: '../models/ImageHash#Interface_ImageHash',

Language: "../models/Language#Interface_Language",

MembershipRequest:
"../models/MembershipRequest#Interface_MembershipRequest",

Message: "../models/Message#Interface_Message",

Organization: "../models/Organization#Interface_Organization",

Plugin: "../models/Plugin#Interface_Plugin",

PluginField: "../models/PluginField#Interface_PluginField",

Post: "../models/Post#Interface_Post",

Task: "../models/Task#Interface_Task",

User: "../models/User#Interface_User",
},

useTypeImports: true,
},
},
},
};

export default config;
Loading

0 comments on commit 650f038

Please sign in to comment.