Skip to content

Golang GraphQL backend using gqlgen for my personal site

Notifications You must be signed in to change notification settings

sockleblu/digital_garden_backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mkdir blog_backend cd blog_backend go mod init github.com/sockleblu/blog_backend go get github.com/99designs/gqlgen

go run github.com/99designs/gqlgen init

To regenerate code after changes

go run github.com/99designs/gqlgen generate

Create User

mutation CreateUser ($input: UserInput!) {
  createUser(input: $input) {
    id
    username
    email
    token
  }
}

Query Variables:

{
  "input": {
    "username": "test_username",
    "password": "test_password",
    "email": "test@email.com"
  }
}

Create Article

mutation CreateArticleMutation($input: ArticleInput!) {
        createArticle(input: $input) {
            id
    				slug
            title
            content
            user {
                id
                username
                email
            }
        }
    }

Query Variables:

{
  "input": {
    "title": "hello there!",
    "tags": [
      {
       "tag": "new_tag"
      }
    ],
    "content": "Umm hi..."
  }
}

Header Variables:

{
 "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDk0ODc1MTksInVzZXJuYW1lIjoic29ja2xlYmx1MSJ9.uYQiGtS3geXkX8tP1Vmk4KO5LaRMJYxMNPVF0iKTVdo"
}

Delete Article

mutation deleteArticleByID ($articleId: Int!) {
  deleteArticleByID(articleId: $articleId)
}

Query Variables:

{
  "articleId": 1
}

Login

mutation Login ($input: LoginInput!) {
  login(input: $input) {
    id
    username
    email
    token
  }
}

Query Variables:

{
  "input": {
    "username": "test_username",
    "password": "test_password",
  }
}

Update Article

mutation updateArticle($articleId: Int!, $input: ArticleInput!) {
  updateArticle(articleId: $articleId, input: $input) {
    id
    content
    slug
  }
}

Query Variables:

{
  "articleId": 22,
  "input": {
    "content": "hey there!",
    "title": "new title",
    "tags": []
  }
}

Articles by Tags

query ArticlesByTags($tagInputs: [TagInput!]!) {
  articlesByTags(tags: $tagInputs) {
    id
    title
    slug
    user {
      username
    }
  }
}

Query Variables

{
  "tagsInput": [
    {
      "tag": "blog"
    },
    {
      "tag": "CORS"
    }
  ]
}

About

Golang GraphQL backend using gqlgen for my personal site

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages