mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
3761
_examples/graphql/schema-first/graph/generated.go
Normal file
3761
_examples/graphql/schema-first/graph/generated.go
Normal file
File diff suppressed because it is too large
Load Diff
66
_examples/graphql/schema-first/graph/model/models_gen.go
Normal file
66
_examples/graphql/schema-first/graph/model/models_gen.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Character struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
IsHero bool `json:"isHero"`
|
||||
CliqueType CliqueType `json:"cliqueType"`
|
||||
}
|
||||
|
||||
type CharacterInput struct {
|
||||
Name string `json:"name"`
|
||||
ID *string `json:"id"`
|
||||
IsHero *bool `json:"isHero"`
|
||||
CliqueType CliqueType `json:"cliqueType"`
|
||||
}
|
||||
|
||||
type CliqueType string
|
||||
|
||||
const (
|
||||
// People who are elite with parents having money
|
||||
CliqueTypeKooks CliqueType = "KOOKS"
|
||||
// People who desperate to move up the social ladder to become new versions of themselves and establish new beginnings
|
||||
CliqueTypePogues CliqueType = "POGUES"
|
||||
)
|
||||
|
||||
var AllCliqueType = []CliqueType{
|
||||
CliqueTypeKooks,
|
||||
CliqueTypePogues,
|
||||
}
|
||||
|
||||
func (e CliqueType) IsValid() bool {
|
||||
switch e {
|
||||
case CliqueTypeKooks, CliqueTypePogues:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e CliqueType) String() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e *CliqueType) UnmarshalGQL(v interface{}) error {
|
||||
str, ok := v.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("enums must be strings")
|
||||
}
|
||||
|
||||
*e = CliqueType(str)
|
||||
if !e.IsValid() {
|
||||
return fmt.Errorf("%s is not a valid CliqueType", str)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e CliqueType) MarshalGQL(w io.Writer) {
|
||||
fmt.Fprint(w, strconv.Quote(e.String()))
|
||||
}
|
||||
11
_examples/graphql/schema-first/graph/resolver.go
Normal file
11
_examples/graphql/schema-first/graph/resolver.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package graph
|
||||
|
||||
import "github.com/iris-contrib/outerbanks-api/graph/model"
|
||||
|
||||
// This file will not be regenerated automatically.
|
||||
//
|
||||
// It serves as dependency injection for your app, add any dependencies you require here.
|
||||
|
||||
type Resolver struct {
|
||||
CharacterStore map[string]model.Character
|
||||
}
|
||||
33
_examples/graphql/schema-first/graph/schema.graphqls
Normal file
33
_examples/graphql/schema-first/graph/schema.graphqls
Normal file
@@ -0,0 +1,33 @@
|
||||
# GraphQL schema example
|
||||
#
|
||||
# https://gqlgen.com/getting-started/
|
||||
|
||||
enum CliqueType {
|
||||
"People who are elite with parents having money"
|
||||
KOOKS
|
||||
"People who desperate to move up the social ladder to become new versions of themselves and establish new beginnings"
|
||||
POGUES
|
||||
}
|
||||
|
||||
type Character {
|
||||
id: ID!
|
||||
name: String!
|
||||
isHero: Boolean!
|
||||
cliqueType: CliqueType!
|
||||
}
|
||||
|
||||
input CharacterInput {
|
||||
name: String!
|
||||
id: String
|
||||
isHero: Boolean
|
||||
cliqueType: CliqueType!
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
upsertCharacter(input: CharacterInput!): Character!
|
||||
}
|
||||
|
||||
type Query {
|
||||
character(id:ID!): Character
|
||||
characters(cliqueType:CliqueType!): [Character!]
|
||||
}
|
||||
77
_examples/graphql/schema-first/graph/schema.resolvers.go
Normal file
77
_examples/graphql/schema-first/graph/schema.resolvers.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package graph
|
||||
|
||||
// This file will be automatically regenerated based on the schema, any resolver implementations
|
||||
// will be copied through when generating and any unknown code will be moved to the end.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/iris-contrib/outerbanks-api/graph/model"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) UpsertCharacter(ctx context.Context, input model.CharacterInput) (*model.Character, error) {
|
||||
id := input.ID
|
||||
var character model.Character
|
||||
character.Name = input.Name
|
||||
character.CliqueType = input.CliqueType
|
||||
|
||||
n := len(r.Resolver.CharacterStore)
|
||||
if n == 0 {
|
||||
r.Resolver.CharacterStore = make(map[string]model.Character)
|
||||
}
|
||||
|
||||
if id != nil {
|
||||
cs, ok := r.Resolver.CharacterStore[*id]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
if input.IsHero != nil {
|
||||
character.IsHero = *input.IsHero
|
||||
} else {
|
||||
character.IsHero = cs.IsHero
|
||||
}
|
||||
r.Resolver.CharacterStore[*id] = character
|
||||
} else {
|
||||
// generate unique id
|
||||
nid := strconv.Itoa(n + 1)
|
||||
character.ID = nid
|
||||
if input.IsHero != nil {
|
||||
character.IsHero = *input.IsHero
|
||||
}
|
||||
r.Resolver.CharacterStore[nid] = character
|
||||
}
|
||||
|
||||
return &character, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) Character(ctx context.Context, id string) (*model.Character, error) {
|
||||
character, ok := r.Resolver.CharacterStore[id]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("not found")
|
||||
}
|
||||
return &character, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) Characters(ctx context.Context, cliqueType model.CliqueType) ([]*model.Character, error) {
|
||||
characters := make([]*model.Character, 0)
|
||||
for idx := range r.Resolver.CharacterStore {
|
||||
character := r.Resolver.CharacterStore[idx]
|
||||
if character.CliqueType == cliqueType {
|
||||
|
||||
characters = append(characters, &character)
|
||||
}
|
||||
}
|
||||
|
||||
return characters, nil
|
||||
}
|
||||
|
||||
// Mutation returns generated.MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
// Query returns generated.QueryResolver implementation.
|
||||
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }
|
||||
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type queryResolver struct{ *Resolver }
|
||||
Reference in New Issue
Block a user