graphql-example-part-1

module
v0.0.0-...-b8d2545 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2024 License: MIT

README


Love my work? Drop me a coffee here. :)

Platforms license

Code of Conduct Support Contribution


GraphQL-based Service with Go-Chi

Global Template Repository for Development and Operations Of Your Projects.

Key Values
Author Muhammad Febrian Ardiansyah
Email mfardiansyah.id@gmail.com
LinkedIn Muhammad Febrian Ardiansyah
Personal Homepage https://mfardiansyah.id

Table of Contents

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

What things you need to install the software and how to install them

apt-get -y install git

Or

yum -y install git
Installation

A step by step series of examples that tell you how to get a development env running

Say what the step will be clone this repository.

git clone git@github.com:ardihikaru/graphql-example-part-1.git
  • Golang linter
  • golang-ci is one of the IMPORTANT packages. Any developer who will maintain this project should install it. The installation command is as follows:
    go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
    
  • Everytime the code is updated, please run following command:
    golangci-lint run ./...
    
    # or this command:
    golangci-lint run ./... --fast -v
    

Development

  • N/A

Usage

Reference and programming instructional materials.

Generate private and public key

  • referenced article
    # generate a private key with the correct length
    openssl genrsa -out private-key.pem 3072
    
    # generate corresponding public key
    openssl rsa -in private-key.pem -pubout -out public-key.pem
    
    # optional: create a self-signed certificate
    openssl req -new -x509 -key private-key.pem -out cert.pem -days 360
    
    # optional: convert pem to pfx
    openssl pkcs12 -export -inkey private-key.pem -in cert.pem -out cert.pfx
    

Using GraphQL Generator

  • Cli command to use (one by one)
go get github.com/99designs/gqlgen@v0.17.45

go run github.com/99designs/gqlgen generate
  • Cli command to use (at once)
go get github.com/99designs/gqlgen@v0.17.45 && go run github.com/99designs/gqlgen generate

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Looking to contribute to our code but need some help? There's a few ways to get information:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Copyright © 2024 Public Use. All Rights Reserved.

Acknowledgments

  • Hat tip to anyone whose code was used
  • Inspiration
  • etc

MISC

  • Validates CORS
curl -v --request OPTIONS 'http://localhost:8080/public/service-id' -H 'Origin: http://other-domain.com' -H 'Access-Control-Request-Method: GET'
curl -v --request OPTIONS 'http://localhost:8080/auth/login' -H 'Origin: http://other-domain.com' -H 'Access-Control-Request-Method: POST'
curl -v -X OPTIONS \
  http://localhost:8080/public/service-id \
  -H 'cache-control: no-cache' \
  -F Origin=http://www.google.com
  • Allowed CORS result (please set cors.Debug: true)
    [cors] 2024/06/16 23:53:13 Handler: Preflight request
    [cors] 2024/06/16 23:53:13 Preflight response headers: map[Access-Control-Allow-Methods:[GET] Access-Control-Allow-Origin:[http://other-domain.com] Access-Control-Max-Age:[6000] Vary:[Origin Access-Control-Request-Method Access-Control-Request-Headers]]
    
  • NOT Allowed CORS result (please set cors.Debug: true)
    [cors] 2024/06/16 23:52:13 Handler: Preflight request
    [cors] 2024/06/16 23:52:13 Preflight aborted: origin 'http://other-domain.com' not allowed
    

Create new module:

kalau ada yg kurang

    go get github.com/99designs/gqlgen@v0.17.45
  1. Create graphqls file for the module: edit graph/graphqls/{module_name}.graphqls

  2. Generate model & resolvers:

    go run github.com/99designs/gqlgen generate
    
  3. Resolvers implementation: edit graph/resolvers/{module_name}.resolvers.go

  4. Run:

    go run server.go 8080
    

Penambahan db Sequence connector

  • config.yaml :
    dbsequser: root
    dbseqpass: 
    dbseqhost: localhost
    dbseqport: 3306
    dbseqname: his_seq
    
  • pemakaian
    db.Handle.Query(q) 
    di ganti menjadi
    db.HandleSeq.Query(q)
    
    db.HandleSeq.Exec(q)
    diganti menjadi 
    db.HandleSeq.Exed(q)
    

Directories

Path Synopsis
cmd
internal
pkg
authenticator
Package authenticator provides functions to authenticate incoming requests
Package authenticator provides functions to authenticate incoming requests
jwtauth
Package jwtauth provides the function for JWT Auth it hosts the old version of github.com/go-chi/jwtauth/v5 (v5.0.2) TODO: needs to update into the latest version instead of this old version
Package jwtauth provides the function for JWT Auth it hosts the old version of github.com/go-chi/jwtauth/v5 (v5.0.2) TODO: needs to update into the latest version instead of this old version
logger
Package logger provides functions to set up a new logger
Package logger provides functions to set up a new logger

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL