Skip to content

Instantly share code, notes, and snippets.

View anujdecoder's full-sized avatar

Anuj A Gupta anujdecoder

  • MindTickle
  • Nagpur
View GitHub Profile
type Query {
character(id: ID): Character
characters: [Character!]!
}
type Mutation {
createCharacter(input: CreateCharacterRequest): Character
}
type Character {
// import "github.com/google/uuid"
type Server struct {
Characters []*Character
}
type Character struct {
Id string
Name string
Type Type
//import "go.appointy.com/jaal/schemabuilder"
func RegisterPayload(schema *schemabuilder.Schema) {
payload := schema.Object("Character", Character{})
payload.FieldFunc("id", func(ctx context.Context, in *Character) *schemabuilder.ID {
return &schemabuilder.ID{Value: in.Id}
})
payload.FieldFunc("name", func(ctx context.Context, in *Character) string {
return in.Name
})
func RegisterInput(schema *schemabuilder.Schema) {
input := schema.InputObject("CreateCharacterRequest", CreateCharacterRequest{})
input.FieldFunc("name", func(target *CreateCharacterRequest, source string) {
target.Name = source
})
input.FieldFunc("type", func(target *CreateCharacterRequest, source Type) {
target.Type = source
})
}
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),
})
}
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)
})
// 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,
package main
import (
"context"
"log"
"net/http"
"go.appointy.com/jaal"
"go.appointy.com/jaal/introspection"
"go.appointy.com/jaal/schemabuilder"
type Broomstick {
id: ID!
name: String!
owner: String!
}
input BroomstickInput {
id: ID
name: String
owner: String
// import "github.com/google/uuid"
type Wand struct {
Id string
Length string
Core string
Wood string
}
type Broomstick struct {