Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Paramanantham Harrison
Paramanantham Harrison

Posted on • Originally published atlearnwithparam.com

Practical example of GraphQL schema design

In this article, we will create a GraphQL schema for a notes app. We will create a schema for creating, updating, deleting and fetching notes. We will then extend the schema to support pagination, custom reports and custom mutations.

typeNote{id:ID!title:String!content:String!categoryId:ID!tags:[String!]!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for creating a note,

typeMutation{createNote(title:String!content:String!categoryId:ID!tags:[String!]!):Note!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for updating a note,

typeMutation{updateNote(id:ID!title:String!content:String!categoryId:ID!tags:[String!]!):Note!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for deleting a note,

typeMutation{deleteNote(id:ID!):Boolean!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for fetching a note,

typeQuery{noteById(id:ID!):Note!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for fetching notes by category,

typeQuery{notesByCategory(categoryId:ID!):[Note!]!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for fetching notes by tags,

typeQuery{notesByTags(tags:[String!]!):[Note!]!}
Enter fullscreen modeExit fullscreen mode

Let's create a schema for fetching all notes and support paginated list,

typeQuery{notes(page:Int,limit:Int):[Note!]!}
Enter fullscreen modeExit fullscreen mode

Let's create custom reports on notes,

typeQuery{notesReport:NotesReport!reportsByCategory:[CategoryReport!]!}typeNotesReport{totalNotes:Int!totalCategories:Int!totalTags:Int!}typeCategoryReport{categoryId:ID!totalNotes:Int!}
Enter fullscreen modeExit fullscreen mode

Now, let's create dedicated custom mutations to

  • update catogory
  • add / remove tag
typeMutation{updateCategory(id:ID!,categoryId:ID!):Note!addTag(id:ID!,tag:String!):Note!removeTag(id:ID!,tag:String!):Note!}
Enter fullscreen modeExit fullscreen mode

Hope you enjoyed the article and learn how to create and extend your graphql schema for your application needs 🙏

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I help beginners to become a pro software engineers through backendchallenges.com
  • Location
    Tallinn, Estonia
  • Work
    Head of Engineering at Jobbatical
  • Joined

More fromParamanantham Harrison

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp