Skip to content

Commit

Permalink
Args
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Feb 3, 2018
1 parent 01896b3 commit f81371e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
27 changes: 18 additions & 9 deletions example/todo/todoresolver/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,38 @@ func (c *ExecutionContext) executeSelectionSet(sel []query.Selection, objectType
resultMap := jsonw.Map{}

for _, collectedField := range groupedFieldSet {
//fieldType := objectType.GetField(collectedField.Name)
//if fieldType == nil {
// continue
//}
resultMap.Set(collectedField.Alias, objectType.Execute(c, objectValue, collectedField.Name, map[string]interface{}{}, collectedField.Selections))

resultMap.Set(collectedField.Alias, objectType.Execute(c, objectValue, collectedField.Name, collectedField.Args, collectedField.Selections))
}
return resultMap
}

type CollectedField struct {
Alias string
Name string
Args map[string]interface{}
Selections []query.Selection
}

func findField(c *[]CollectedField, alias string, name string) *CollectedField {
func findField(c *[]CollectedField, field *query.Field, vars map[string]interface{}) *CollectedField {
for i, cf := range *c {
if cf.Alias == alias {
if cf.Alias == field.Alias.Name {
return &(*c)[i]
}
}

*c = append(*c, CollectedField{Alias: alias, Name: name})
f := CollectedField{
Alias: field.Alias.Name,
Name: field.Name.Name,
}
if len(field.Arguments) > 0 {
f.Args = map[string]interface{}{}
for _, arg := range field.Arguments {
f.Args[arg.Name.Name] = arg.Value.Value(vars)
}
}

*c = append(*c, f)
return &(*c)[len(*c)-1]
}

Expand All @@ -131,7 +140,7 @@ func (c *ExecutionContext) collectFields(objectType Type, selSet []query.Selecti
for _, sel := range selSet {
switch sel := sel.(type) {
case *query.Field:
f := findField(&groupedFields, sel.Alias.Name, sel.Name.Name)
f := findField(&groupedFields, sel, c.variables)
f.Selections = append(f.Selections, sel.Selections...)
default:
panic("Unsupported!")
Expand Down
4 changes: 2 additions & 2 deletions internal/common/literals.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ type BasicLit struct {
func (lit *BasicLit) Value(vars map[string]interface{}) interface{} {
switch lit.Type {
case scanner.Int:
value, err := strconv.ParseInt(lit.Text, 10, 32)
value, err := strconv.ParseInt(lit.Text, 10, 64)
if err != nil {
panic(err)
}
return int32(value)
return int(value)

case scanner.Float:
value, err := strconv.ParseFloat(lit.Text, 64)
Expand Down

0 comments on commit f81371e

Please sign in to comment.