Example of the changes necessary to add a new service with simple data field declaration and mock data, can be found here: #2
-
Create properly named service folder inside
server/api
. -
Create properly named service folder inside
server/domain
. -
Copy
index.ts
fromtemplates/api
intoserver/api/<SERVICE_NAME>
and follow the instructions inside the file. -
Copy all files from
templates/domain
intoserver/domain/<SERVICE_NAME>
and follow the instructions inside them. -
Add
<SERVICE_NAME>
to thecategories
object insideexplorer/src/shared/categories/categories.ts
. -
Open
server/shared/graphql/available-categories.ts
and add<SERVICE_NAME>
array, looking like the following:const serviceName = ["example"]; export const availableCategories = { serviceName, facebook, ... };
- If the desired field is not on the list for given service inside
explorer/src/shared/categories/categories.ts
, add it there. - Add the desired field in
server/domain/<SERVICE_NAME>/shema.graphql
. - Add
<DESIRED_FIELD>: true
to the<SERVICE_NAME>Keys
object in theserver/shared/graphql/available-categories.ts
file
- Add the desired data in
server/domain/<SERVICE_NAME>/data.ts
under the proper field.
To get the values for environmental variables REACT_APP_FORM_URL
and REACT_APP_FORM_QUERY_FIELD_ID
, You have to:
-
Create google form
-
Add a question with answer type of
paragraph
-
Go to three dots in the top-right and click "Get pre-filled link"
-
Type anything in the created field
-
Submit with the "Get link" button and click "COPY LINK" in the toast
-
The pasted link should look like this:
-
Given the above link, the variables would be:
REACT_APP_FORM_URL = https://docs.google.com/forms/d/e/1FAIpQLSflSJE8cn3jEvWgw3IBMRBJST0GUWIGokCnT620A3dc97qETw/viewform REACT_APP_FORM_QUERY_FIELD_ID = 214069913
This section complements the previous one to keep the codebase clean and scalable. This is the preferred way of adding anything to the schema and should be followed if possible. All steps mentioned here can also be done retroactively.
In addition to the steps described above, proper Typescript types should be provided and the service should be able to be run locally.
-
Run
npm run gen:gql
to generate the graphql types for the newly created service. -
In
server/domain/<SERVICE_NAME>/types.ts
, update theany
with a previously generated graphql service type. -
In
server/domain/<SERVICE_NAME>/resolvers.ts
You should be able to simply remove all of the castings toany
. -
In
package.json
add a following script, replacing all<SERVICE_NAME>
s with proper name:"start:<SERVICE_NAME>": "nodemon --ext ts,graphql --watch shared --watch api/<SERVICE_NAME> --watch domain/<SERVICE_NAME> --exec 'npm run node -- api/<SERVICE_NAME>/index.ts'",
Note: the base list of categories is automatically generated from the folder names of the data exported from the services. Some fields will be naturally missing, as the structure of the exported data varies between the services. The script is in explorer/scripts/gen-categories.js
and it generates data based on the data
folder on the root level (git ignored, no actual data is commited to the repo).
The only upgrade from manual schema fields addition is in the server/shared/graphql/available-categories.ts
, as the fields can be safeguarded by typescript types (replace any
s with proper types). For the generated types see the first step of "Adding services" section above.
There is a dedicated script for data generation in server/scripts/gen-mocks.ts
which can be run with npm run gen:data
(or npm run gen:data:clean
if you want to replace/modify the existing files - note that any manual changes will be discarded if you do this).
It is updated at the moment of writing, but to be usable, it will have to be brought back up to date with the data created manually.
Usage steps:
- Go to
server/api/<SERVICE_NAME>/data-generator.ts
and add/update a generator for the service, mirroring the existing ones. - Go to
server/scripts/gen-mocks.ts
and add a call to the new generator in thegenerateData
function.
npm install && npm start
We've got MaterialUI and Tailwind set up. Might be worth to improve the consistency of usage across the app.
npm install && npm start
Webpack aliases are not working with Vercel serverless with the present config.