Skip to content

Instantly share code, notes, and snippets.

View anujdecoder's full-sized avatar

Anuj A Gupta anujdecoder

  • MindTickle
  • Nagpur
View GitHub Profile
package main
import (
"context"
"github.com/google/uuid"
"log"
"net/http"
"go.appointy.com/jaal"
"go.appointy.com/jaal/introspection"
func main() {
s := &Server{
Wands: []*Wand{},
Broomsticks: []*Broomstick{},
Snakes: []*Snake{},
Spiders: []*Spider{},
}
sb := schemabuilder.NewSchema()
RegisterWand(sb)
type MagicalObject struct {
schemabuilder.Union
*Wand
*Broomstick
}
func (s *Server) RegisterUnion(sb *schemabuilder.Schema) {
sb.Query().FieldFunc("magicalObject", func(ctx context.Context, args struct {
Id schemabuilder.ID
}) *MagicalObject {
type MagicalCreature struct {
schemabuilder.Interface
*Spider
*Snake
}
func (s *Server) RegisterInterface(sb *schemabuilder.Schema) {
sb.Query().FieldFunc("magicalCreature", func(ctx context.Context, args struct {
Id schemabuilder.ID
}) *MagicalCreature {
// import "github.com/google/uuid"
type Wand struct {
Id string
Length string
Core string
Wood string
}
type Broomstick struct {
type Broomstick {
id: ID!
name: String!
owner: String!
}
input BroomstickInput {
id: ID
name: String
owner: String
package main
import (
"context"
"log"
"net/http"
"go.appointy.com/jaal"
"go.appointy.com/jaal/introspection"
"go.appointy.com/jaal/schemabuilder"
// import "go.appointy.com/jaal"
// import "go.appointy.com/jaal/introspection"
// import "github.com/google/uuid"
func main() {
s := &Server{
Characters: []*Character{{
Id: uuid.New().String(),
Name: "Harry Potter",
Type: WIZARD,
func (s *Server) RegisterOperations(schema *schemabuilder.Schema) {
schema.Query().FieldFunc("character", func(ctx context.Context, args struct {
Id *schemabuilder.ID
}) *Character {
return s.GetCharacter(ctx, args.Id.Value)
})
schema.Query().FieldFunc("characters", func(ctx context.Context, args struct{}) []*Character {
return s.ListCharacters(ctx)
})
func RegisterEnum(schema *schemabuilder.Schema) {
schema.Enum(Type(0), map[string]interface{}{
"WIZARD": Type(0),
"MUGGLE": Type(1),
"GOBLIN": Type(2),
"HOUSE_ELF": Type(3),
})
}