Adding graphql resolver to HackaTalk server

Hyo
dooboolab
Published in
2 min readFeb 9, 2020

I’d like to share how to add new resolvers to already implemented graphql server HackaTalk

Figure 1: Example RDBMS for newly added [Gallery] model

Here, I’d like to add Gallery model which is a table that has columns photoURL and anid which is a primary key.

When you are just adding a new table to an existing database without changing any other table’s association, you don’t need to generate any migration script from sequelize. Let’s create Gallery model.

  1. Add sequelize model.
Figure 2: Gallery model for sequelize

2. Import Gallery model so it will export root models to index.ts.

Figure 3: Example of importing Gallery model to model index

3. Create gallery.graphql in src/schemas.

Figure 4: Gallery schema which is created as gallery.graphql

4. Import grallery.graphql in schema.graphql which is a root of schemas.

5. Let’s add a few resolvers for this model.

Figure 5: Newly created resolvers are boxed

6. Run graphql-codegen.

Figure 6: graphql-codegen ran successfully

7. Create gallery.ts in resolver dir.

Figure 7: New file added to resolvers

8. Implement resolvers.

Figure 8: Source code for `gallery` resolvers

It is done for adding new resolvers to the running HackaTalk server. You can check out the pull request to find out more about it 💃.

P.S. We will work on the test code in the future post!

--

--