Skip to content

Commit 29488c2

Browse files
dblythyTomWFox
andauthored
Contributing Blog (#31)
* Contributing Blog * Update _config.yml * Update 2020-12-16-Contributing-to-Parse-Server.md * add extra categories and change date * change file name Co-authored-by: Tom Fox <[email protected]>
1 parent 07cb4ed commit 29488c2

File tree

2 files changed

+188
-86
lines changed

2 files changed

+188
-86
lines changed

_config.yml

+4-86
Original file line numberDiff line numberDiff line change
@@ -70,92 +70,10 @@ authors:
7070
byline: Core Contributor
7171
github: tomwfox
7272
twitter: T0mfox
73+
dblythy:
74+
name: Daniel Blyth
75+
github: dblythy
76+
byline: Parse Contributor
7377
# Original Parse Team
74-
courtneywitmer:
75-
name: Courtney Witmer
76-
andrewimm:
77-
name: Andrew Imm
7878
foscomarotto:
7979
name: Fosco Marotto
80-
bennham:
81-
name: Ben Nham
82-
listiarsowastuargo:
83-
name: Listiarso Wastuargo
84-
christineyen:
85-
name: Christine Yen
86-
beardouglas:
87-
name: Bear Douglas
88-
mattieugamacheasselin:
89-
name: Mattieu Gamache-Asselin
90-
ashleysmith:
91-
name: Ashley Smith
92-
hectorramos:
93-
name: Héctor Ramos
94-
abhishekkona:
95-
name: Abhishek Kona
96-
christophetauziet:
97-
name: Christophe Tauziet
98-
charitymajors:
99-
name: Charity Majors
100-
ilyasukhar:
101-
name: Ilya Sukhar
102-
grantlandchew:
103-
name: Grantland Chew
104-
bryanklimt:
105-
name: Bryan Klimt
106-
naitikshah:
107-
name: Naitik Shah
108-
nancyxiao:
109-
name: Nancy Xiao
110-
kailiu:
111-
name: Kai Liu
112-
stanleywang:
113-
name: Stanley Wang
114-
christineabernathy:
115-
name: Christine Abernathy
116-
jamiekarraker:
117-
name: Jamie Karraker
118-
karangajwani:
119-
name: Karan Gajwani
120-
thomasbouldin:
121-
name: Thomas Bouldin
122-
nikitalutsenko:
123-
name: Nikita Lutsenko
124-
georgekedenburgiii:
125-
name: George Kedenburg III
126-
devincheevers:
127-
name: Devin Cheevers
128-
jamesyu:
129-
name: James Yu
130-
parse:
131-
name: Parse
132-
mikekania:
133-
name: Mike Kania
134-
ronaldyang:
135-
name: Ronald Yang
136-
björnkaiser:
137-
name: Björn Kaiser
138-
pavanathivarapu:
139-
name: Pavan Athivarapu
140-
drewgross:
141-
name: Drew Gross
142-
ericnakagawa:
143-
name: Eric Nakagawa
144-
vítorfernandes:
145-
name: Vítor Fernandes
146-
damiankowalewski:
147-
name: Damian Kowalewski
148-
travisredman:
149-
name: Travis Redman
150-
mengyanwang:
151-
name: Mengyan Wang
152-
georgeyakovlev:
153-
name: George Yakovlev
154-
richardross:
155-
name: Richard Ross
156-
jakeblakeley:
157-
name: Jake Blakeley
158-
kevinlacker:
159-
name: Kevin Lacker
160-
patrickpelletier:
161-
name: Patrick Pelletier
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
layout: post
3+
title: How to start contributing to Parse Server
4+
date: 2021-02-14 15:00 +0100
5+
comments: true
6+
author: dblythy
7+
categories: [Learn, Tutorial, Community, NodeJS]
8+
---
9+
10+
The most amazing feature of Parse Server is that it's accessible for developers of all skill levels.
11+
12+
Personally, I started playing around with Objective-C in 2012.
13+
14+
Parse was a way for me to build a complete online app, without having the in-depth knowledge of _how_ to build networking, storage, user systems, etc.
15+
16+
The more I built with Parse, the more I learnt JavaScript, which has fortunately allowed me to contribute to Parse Server.
17+
18+
Although it might seem daunting, contributing to our great open-source project is encouraged to all developers, and in this blog post, I'm going to give you an insight as to how.
19+
20+
<!-- more -->
21+
22+
## Cloning Parse Server
23+
24+
Ok. I like to use GitHub desktop as it's a visual git tool and sometimes I find git to be confusing. The first step after installing is to make a copy (or "clone") of the Parse Server repo locally.
25+
26+
- Press _File_ > _Clone Repository_, select 'url' and type [https://github.com/parse-community/parse-server](https://github.com/parse-community/parse-server)
27+
28+
<img width="960" alt="Cloning Parse Server" src="https://user-images.githubusercontent.com/4974769/102356603-8676a700-4001-11eb-8c8a-a9a2be910b57.png">
29+
30+
Next, select "Clone".
31+
32+
Ok, great! Now we have a local copy of Parse Server.
33+
34+
## Creating a Branch
35+
36+
In order to add code to Parse Server, we need to create a "Branch". This allows git to track any differences from our "Branch" vs the "master" branch, so we can hopefully merge our changes with the main project in the future.
37+
38+
First, set current repository to the clone of Parse Server, and then press the branch.
39+
40+
<img width="960" alt="Creating a Branch" src="https://user-images.githubusercontent.com/4974769/102357283-495ee480-4002-11eb-9c95-d84982e135b2.png">
41+
42+
Next, select "New Branch. Name your branch appropriately according to the feature you are working on.
43+
44+
<img width="960" alt="Creating a Branch" src="https://user-images.githubusercontent.com/4974769/102357356-52e84c80-4002-11eb-8066-5285e3fb8791.png">
45+
46+
For this blog post, I am working on adding `request.context` to an `afterFind` trigger, so I will name this branch `afterFind-context`.
47+
48+
## Diving in
49+
50+
Ok, now for the fun part! Next, select "Open the repository in your external editor". I am using Visual Studio Code.
51+
52+
You will notice there are a lot of files here. Don't be alarmed, we _try_ to keep things as intuitive and organized as possible.
53+
54+
Let's open a new terminal and run `npm run watch` so that changes to the src folder take effect.
55+
56+
<img width="960" alt="npm run watch" src="https://user-images.githubusercontent.com/4974769/102359017-60063b00-4004-11eb-861e-7ac457d44413.png">
57+
58+
<img width="960" alt="Screen Shot 2020-12-17 at 1 08 04 am" src="https://user-images.githubusercontent.com/4974769/102359009-5d0b4a80-4004-11eb-92ed-d2c1c62f34ec.png">
59+
60+
61+
### Spec Files
62+
63+
The first thing I like to do for an issue like this, is write a failing test case so I can be clear as to what I am fixing.
64+
65+
If you're not familiar with test cases, they are essentially javascript files that automatically test and ensure that logic prevails. Parse Server uses Jasmine tests to ensure that new features do not affect existing functionality.
66+
67+
You will find all the Parse Server testing under `/spec`.
68+
69+
The issue I am fixing is related to Cloud Code, so the spec file I am adding to is `CloudCode.spec.js`.
70+
71+
<img width="960" alt="Screen Shot 2020-12-17 at 1 16 15 am" src="https://user-images.githubusercontent.com/4974769/102359907-795bb700-4005-11eb-93fe-a37ac966eb2a.png">
72+
73+
Here I have added my new test. You will notice that the code here is the same as you'd use in Parse Cloud code, with a few small changes.
74+
75+
- `it` is used to tell Jasmine that this is a new test. `fit` is so that Jasmine will only run this test whilst I debug.
76+
- `expect` is Jasmine method used to ensure expected outcomes of logic. In is example, an error will be thrown if `request.context.a` is not `a`.
77+
78+
To run this test, click _Terminal_ > _Split Terminal_ and in the new terminal window, type `npm test spec/CloudCode.spec.js`. This might take a moment.
79+
80+
Here are the results:
81+
82+
<img width="960" alt="Screen Shot 2020-12-17 at 1 26 31 am" src="https://user-images.githubusercontent.com/4974769/102361054-e754ae00-4006-11eb-87d6-6c07d0b6e729.png">
83+
84+
As expected, the test failed with "Error: Cannot read property 'a' of undefined". This confirms that this is indeed a bug, or a feature that is yet to be extended. So let's get to work!
85+
86+
## Isolating and Fixing
87+
88+
It can be daunting at first to work out where the changes need to be made. The Parse Core team and other contributors are always happy to give tips and pointers and would rather your time not go wasted, so always feel free to ask in the [community forum](https://community.parseplatform.org). The [notable files](https://docs.parseplatform.org/parse-server/guide/#notable-files) is also a good resource too. It's unrealistic for us to expect _anyone_ new to be fully across the code base, so there is no shame in asking for pointers.
89+
90+
The file I am working on to start is `Triggers.js`. Here's the process I went to find that:
91+
92+
- `Parse.Cloud.js` is where the cloud functions are handled, and the afterFind section has the code: `triggers.Types.afterFind`
93+
- Searching the project (control / command F) for `triggers.Types.afterFind` reveals `RestQuery.js`
94+
- `RestQuery.js` has a function `RestQuery.prototype.runAfterFindTrigger` that calls the trigger, `triggers.maybeRunAfterFindTrigger`, which is located in `Triggers.js`
95+
96+
Looking at the other functions, they all have `context` passed to them, but `maybeRunAfterFindTrigger` does not. Let's try apply the existing logic to `maybeRunAfterFindTrigger`
97+
98+
No `context`:
99+
<img width="960" alt="Screen Shot 2020-12-17 at 1 44 33 am" src="https://user-images.githubusercontent.com/4974769/102363348-71057b00-4009-11eb-8b73-6868bd1b3815.png">
100+
101+
`context`:
102+
<img width="960" alt="Screen Shot 2020-12-17 at 1 45 17 am" src="https://user-images.githubusercontent.com/4974769/102363445-867aa500-4009-11eb-9d74-1388a551430d.png">
103+
104+
So, let's add `context` in, as it is in the other functions:
105+
106+
<img width="960" alt="Screen Shot 2020-12-17 at 1 46 59 am" src="https://user-images.githubusercontent.com/4974769/102363696-c3469c00-4009-11eb-8413-318b4e6db547.png">
107+
108+
We also need to add the afterFind type to triggers with context:
109+
110+
<img width="960" alt="Screen Shot 2020-12-17 at 2 32 31 am" src="https://user-images.githubusercontent.com/4974769/102369592-3c48f200-4010-11eb-8541-e82dfc4eee4c.png">
111+
112+
Cool! However, when I searched `maybeRunAfterFindTrigger`, I noticed that no context element was passed from RestQuery. So we'll add that:
113+
114+
<img width="960" alt="Screen Shot 2020-12-17 at 1 49 28 am" src="https://user-images.githubusercontent.com/4974769/102363990-1b7d9e00-400a-11eb-95b5-03c5fb9bc3df.png">
115+
116+
Next, `context` is never passed to `RestQuery.js`, so it won't know what `this.context` is. Let's add that too, with a similar pattern to `RestWrite.js`:
117+
118+
<img width="960" alt="Screen Shot 2020-12-17 at 1 51 45 am" src="https://user-images.githubusercontent.com/4974769/102364345-6f888280-400a-11eb-9882-c945db735ecc.png">
119+
120+
Ok great. Now we've got to pass the final context parameter to `RestQuery.js`, and then we should be good to run our test again. The context argument needs to be added to `new RestQuery(...` in `rest.js`
121+
122+
<img width="960" alt="Screen Shot 2020-12-17 at 2 00 57 am" src="https://user-images.githubusercontent.com/4974769/102368856-7239a680-400f-11eb-91fb-b813be492c74.png">
123+
124+
125+
## Re-running the tests
126+
127+
I'm _pretty sure_ I've added context everywhere it's needed. I can always come back and continue editing the files, or temporarily add `console.log` in a few places to work out what's going on.
128+
129+
Let's run `npm test spec/CloudCode.spec.js` and see if the test passes:
130+
131+
### Result:
132+
```
133+
Started
134+
.
135+
136+
137+
Ran 1 of 130 specs
138+
1 spec, 0 failures
139+
```
140+
141+
Awesome, this means that the test passed and `request.context` is now available in `afterFind` triggers!
142+
143+
## Preparing for Merge
144+
145+
In order to merge with the master repo, let's check a few things:
146+
147+
- Replace `fit` in tests with `it`. It's important that all new code added by the new features are captured by tests, so write more tests if required.
148+
- Run `npm test` to make sure the new feature doesn't break any other feature
149+
- Run `npm run prettier` to clean up code style
150+
- Run `npm run lint-fix` to fix any lint issues
151+
- Run `npm run lint` to identify any remaining lint issues
152+
- Add our changes to the changelog
153+
154+
So, we're all good to go! Let's jump back into GitHub desktop.
155+
156+
## Publishing your Branch
157+
158+
<img width="960" alt="Screen Shot 2020-12-17 at 2 38 12 am" src="https://user-images.githubusercontent.com/4974769/102370204-ea549c00-4010-11eb-9993-d3d8b5edf2ac.png">
159+
160+
Here you can review all the changes you've made compared to the master branch. In order to upload these changes, type in a summary, and press _Commit_.
161+
162+
- If you see "You do not have write access to Parse-Server. Want to create a fork?", press _Create a Fork_, and then _Fork this Repository_
163+
164+
The summary of the first commit is what will show under GitHub file structures, so I try to give a little explanation here.
165+
166+
Today I'll use:
167+
168+
**Fix: context for afterFind**
169+
170+
Next, hit _Publish Branch_.
171+
172+
Now, your branch is available on GitHub. You can install this fork and test it on your own Parse Server using `npm install github:myUsername/parse-server#my-awesome-feature`.
173+
174+
GitHub Desktop will now say "Create a pull request from your current branch". Press _Create Pull Request_. This will open GitHub in your browser to create a pull request (aka PR) that will add your changes to the master repo.
175+
176+
All you have to do from here, is fill out the form, and hit _Create Pull Request_. The core Parse Team will review your changes, provide feedback, and eventually merge the changes with the master.
177+
178+
[You can see my PR for this feature here.](https://github.com/parse-community/parse-server/pull/7078)
179+
180+
**And that's all! You're on the way to becoming a Parse Contributor!**
181+
182+
Remember, if you're willing to contribute to our amazing project, the Core Team and many other contributors (such as myself 🤩) will be more than happy to help you learn. We are after all, a community.
183+
184+
Thanks for reading!

0 commit comments

Comments
 (0)