diff --git a/.YetAnotherToDoList.yaml b/.YetAnotherToDoList.yaml index ff9f05a..0991163 100644 --- a/.YetAnotherToDoList.yaml +++ b/.YetAnotherToDoList.yaml @@ -1,4 +1,4 @@ -sqlite3_file: "YetAnotherToDoList.sqlite3" -log_file: "YetAnotherToDoList.log" +sqlite3_file: 'YetAnotherToDoList.sqlite3' +log_file: 'YetAnotherToDoList.log' log_UTC: false port: 4242 diff --git a/CMD_HISTORY.md b/CMD_HISTORY.md index 1a2a437..2a50335 100644 --- a/CMD_HISTORY.md +++ b/CMD_HISTORY.md @@ -5,10 +5,13 @@ Commands were run in the order listed below on a debian based system. ## Initial setup - Initialize go module + ```bash go mod init somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList ``` -- Install cobra-cli (try `~/go/bin/cobra-cli` if `cobra-cli` can not be found in your `PATH`) + +- Install cobra-cli (try `~/go/bin/cobra-cli` if `cobra-cli` can not be found in + your `PATH`) ```bash go install github.com/spf13/cobra-cli@latest @@ -16,14 +19,19 @@ Commands were run in the order listed below on a debian based system. ``` - Add missing modules + ```bash go mod tidy ``` + - Add license command + ```bash cobra-cli add license ``` + - Add qglgen + ```bash printf '// +build tools\npackage tools\nimport (_ "github.com/99designs/gqlgen"\n _ "github.com/99designs/gqlgen/graphql/introspection")' | gofmt > tools.go go mod tidy @@ -31,9 +39,11 @@ Commands were run in the order listed below on a debian based system. go mod tidy cobra-cli add server ``` + - Add go-sqlite3 + ```bash go get github.com/mattn/go-sqlite3 CGO_ENABLED=1 go install github.com/mattn/go-sqlite3 # you may need to install gcc if not already present go mod tidy - ``` \ No newline at end of file + ``` diff --git a/INSTALL.md b/INSTALL.md index 7c34f26..93c01c2 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -8,7 +8,8 @@ include_toc: true ## Requirements: - go 1.21.1 (not tested, but _should_ also work in all versions since 1.16) -- gcc 4.6+ (according to the [golang wiki](https://github.com/golang/go/wiki/MinimumRequirements#cgo)) +- gcc 4.6+ (according to the + [golang wiki](https://github.com/golang/go/wiki/MinimumRequirements#cgo)) ## Install via `go install` @@ -18,11 +19,13 @@ When installing via this method, no commit & version information is provided. go install somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList@latest ``` -You can specify the installation location by adding `GOBIN=` +You can specify the installation location by adding +`GOBIN=` ## Install from git repository (Recommended) -In addition to the [requirements](#requirements), you will need `git` and `GNU make` +In addition to the [requirements](#requirements), you will need `git` and +`GNU make` ```bash git clone https://somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList.git @@ -45,7 +48,9 @@ There are currently no pre-build binaries available ## Troubleshooting -If you get an error like `Unable to connect: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub`, make sure `gcc` is installed and in your `PATH`. +If you get an error like +`Unable to connect: Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub`, +make sure `gcc` is installed and in your `PATH`. If this still does not work, try @@ -73,7 +78,8 @@ YetAnotherToDoList help completion ### Configuration -Edit the file [.YetAnotherToDoList.yaml](./.YetAnotherToDoList.yaml) and run `YetAnotherToDoList help` for options. +Edit the file [.YetAnotherToDoList.yaml](./.YetAnotherToDoList.yaml) and run +`YetAnotherToDoList help` for options. ## Uninstall @@ -83,7 +89,8 @@ Run `make uninstall` or rm $HOME/.local/bin/YetAnotherToDoList # replace with your installation path ``` -Don't forget to delete the `.log`, `.yaml` and `.sqlite3` files if you don't need them any more. +Don't forget to delete the `.log`, `.yaml` and `.sqlite3` files if you don't +need them any more. ### Remove shell completion diff --git a/README.md b/README.md index 634d0fd..2893c58 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ # YetAnotherToDoList -A simple To Do List Web Application with Go backend, Vue.js frontend and a GraphQL API. +A simple To Do List Web Application with Go backend, Vue.js frontend and a +GraphQL API. -This is a simple project I created to learn the [Go](https://go.dev/) language, [GraphQL](https://graphql.org/) and [Vue.js](https://vuejs.org). +This is a simple project I created to learn the [Go](https://go.dev/) language, +[GraphQL](https://graphql.org/) and [Vue.js](https://vuejs.org). Instructions on how to install can be found in [INSTALL.md](./INSTALL.md). -Once installed, you might want to run the queries in [example.graphql](./example.graphql). +Once installed, you might want to run the queries in +[example.graphql](./example.graphql). ## Contributing diff --git a/example.graphql b/example.graphql index 3f1b0c2..3e03d52 100644 --- a/example.graphql +++ b/example.graphql @@ -1,77 +1,77 @@ # you first have to add a user to create todos query getUser { - user(id: 1) { - id - userName - fullName - todos { - id - text - done - } - } + user(id: 1) { + id + userName + fullName + todos { + id + text + done + } + } } query getTodo { - todo(id: 1) { - id - text - done - } + todo(id: 1) { + id + text + done + } } query getTodos { - todos { - id - text - done - user { - id - userName - fullName - todos { - id # you could continue this - } - } - } + todos { + id + text + done + user { + id + userName + fullName + todos { + id # you could continue this + } + } + } } query getUsers { - users { - id - userName - fullName - todos { - id # ...and this too - } - } + users { + id + userName + fullName + todos { + id # ...and this too + } + } } mutation createTodo { - createTodo(input: { userId: 2, text: "adding a router and CSRF header" }) { - id - text - done - } + createTodo(input: { userId: 2, text: "adding a router and CSRF header" }) { + id + text + done + } } mutation updateTodo { - updateTodo(id: 1, changes: { done: true }) { - id - text - done - } + updateTodo(id: 1, changes: { done: true }) { + id + text + done + } } mutation createUser { - createUser(input: { userName: "1234Lorem", fullName: "Lorem I." }) { - id - } + createUser(input: { userName: "1234Lorem", fullName: "Lorem I." }) { + id + } } mutation updateUser { - updateUser(id: "1", changes: { fullName: "Lorem Ipsum" }) { - fullName - } + updateUser(id: "1", changes: { fullName: "Lorem Ipsum" }) { + fullName + } } diff --git a/gqlgen.yml b/gqlgen.yaml similarity index 76% rename from gqlgen.yml rename to gqlgen.yaml index 49f96e7..58104b4 100644 --- a/gqlgen.yml +++ b/gqlgen.yaml @@ -15,12 +15,12 @@ # Where are all the schema files located? globs are supported eg src/**/*.graphqls schema: - - graph/*.graphqls + - graph/*.graphqls # Where should the generated server code go? exec: - filename: graph/generated.go - package: graph + filename: graph/generated.go + package: graph # Uncomment to enable federation # federation: @@ -29,17 +29,17 @@ exec: # Where should any generated models go? model: - filename: graph/model/models_gen.go - package: model + filename: graph/model/models_gen.go + package: model # Where should the resolver implementations go? resolver: - layout: follow-schema - dir: graph - package: graph - filename_template: "{name}.resolvers.go" - # Optional: turn on to not generate template comments above resolvers - # omit_template_comment: false + layout: follow-schema + dir: graph + package: graph + filename_template: '{name}.resolvers.go' + # Optional: turn on to not generate template comments above resolvers + # omit_template_comment: false # Optional: turn on use ` + "`" + `gqlgen:"fieldName"` + "`" + ` tags in your models # struct_tag: json @@ -81,7 +81,7 @@ resolver: # gqlgen will search for any type names in the schema in these go packages # if they match it will use them, otherwise it will generate them. autobind: - - "somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/graph/model" + - 'somepi.ddns.net/gitea/gilex-dev/YetAnotherToDoList/graph/model' # This section declares type mapping between the GraphQL and go type systems # @@ -89,22 +89,22 @@ autobind: # modelgen, the others will be allowed when binding to fields. Configure them to # your liking models: - ID: - model: - - github.com/99designs/gqlgen/graphql.ID - - github.com/99designs/gqlgen/graphql.Int - - github.com/99designs/gqlgen/graphql.Int64 - - github.com/99designs/gqlgen/graphql.Int32 - Int: - model: - - github.com/99designs/gqlgen/graphql.Int - - github.com/99designs/gqlgen/graphql.Int64 - - github.com/99designs/gqlgen/graphql.Int32 - Todo: - fields: - user: - resolver: true - User: - fields: - todos: - resolver: true + ID: + model: + - github.com/99designs/gqlgen/graphql.ID + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 + Int: + model: + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 + Todo: + fields: + user: + resolver: true + User: + fields: + todos: + resolver: true diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 226b736..b4e702b 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -18,51 +18,51 @@ # https://gqlgen.com/getting-started/ type Todo { - id: ID! - text: String! - done: Boolean! - user: User! + id: ID! + text: String! + done: Boolean! + user: User! } type User { - id: ID! - userName: String! - fullName: String! - todos: [Todo!]! + id: ID! + userName: String! + fullName: String! + todos: [Todo!]! } type Query { - todos: [Todo!]! - users: [User!]! - user(id: ID!): User! - todo(id: ID!): Todo! + todos: [Todo!]! + users: [User!]! + user(id: ID!): User! + todo(id: ID!): Todo! } input NewUser { - userName: String! - fullName: String! + userName: String! + fullName: String! } input NewTodo { - text: String! - userId: ID! + text: String! + userId: ID! } input updateTodo { - text: String - done: Boolean + text: String + done: Boolean } input updateUser { - userName: String - fullName: String + userName: String + fullName: String } type Mutation { - createUser(input: NewUser!): User! - createTodo(input: NewTodo!): Todo! - updateTodo(id: ID!, changes: updateTodo!): Todo! - updateUser(id: ID!, changes: updateUser!): User! - deleteUser(id: ID!): ID - deleteTodo(id: ID!): ID + createUser(input: NewUser!): User! + createTodo(input: NewTodo!): Todo! + updateTodo(id: ID!, changes: updateTodo!): Todo! + updateUser(id: ID!, changes: updateUser!): User! + deleteUser(id: ID!): ID + deleteTodo(id: ID!): ID }