Skip to content

Instantly share code, notes, and snippets.

View VictorKabata's full-sized avatar
💻
Knock, knock. Race condition. Who's there?

Victor Kabata VictorKabata

💻
Knock, knock. Race condition. Who's there?
View GitHub Profile
// Greet -> build.gradle.kts
tasks.matching { it.name != "loadMamboMotoFile" }.all {
println("Executing task: ${this.name}")
this.dependsOn("loadMamboMotoFile")
}
tasks.register("loadMamboMotoFile") {
println("Executing task: ${this.name}")
package main
import (
"fmt"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"log"
"net/http"
"time"
)
fields := graphql.Fields{
"notes": &graphql.Field{
Name: "Get all notes",
Type: graphql.NewList(noteType),
Description: "Get list of all notes",
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
return notes, nil
},
},
...
"note": &graphql.Field{
Name: "Get note by ID",
Type: noteType,
Description: "Get note by ID",
Args: graphql.FieldConfigArgument{"id": &graphql.ArgumentConfig{Type: graphql.Int}},
Resolve: func(params graphql.ResolveParams) (interface{}, error) {
id, isValid := params.Args["id"].(int)
if isValid {
@VictorKabata
VictorKabata / graphql-go.go
Created October 29, 2022 16:50
Simple graphQL API built using Golang
package main
import (
"fmt"
"github.com/graphql-go/graphql"
"github.com/graphql-go/handler"
"log"
"net/http"
"time"
)
go get github.com/graphql-go/graphql // GraphQL-Go
go get github.com/graphql-go/handler // GraphQL-Go-Handler
...
var sandboxHTML = []byte(`
<!DOCTYPE html>
<html lang="en">
<body style="margin: 0; overflow-x: hidden; overflow-y: hidden">
<div id="sandbox" style="height:100vh; width:100vw;"></div>
<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script>
<script>
new window.EmbeddedSandbox({
log.Fatal(http.ListenAndServe(":8080", nil))
handler := handler.New(&handler.Config{
Schema: &schema,
Pretty: true,
GraphiQL: false,
})
http.Handle("/graphql", handler)
schemaConfig := graphql.SchemaConfig{Query: graphql.NewObject(rootQuery)}
schema, err := graphql.NewSchema(schemaConfig)
if err != nil {
log.Fatalf("Failed to create graphql schema: %v", err)
}