Skip to content

Commit

Permalink
refactor: Exposed private functions necessary for schema/ast type par…
Browse files Browse the repository at this point in the history
…sing (#8)

* Exposed private functions necessary for schema/ast type parsing

* Properly handling nullType AST value conversion for gql.List types
  • Loading branch information
jsimnz authored and fredcarle committed Apr 25, 2023
1 parent e28541e commit 1db5193
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,10 @@ func getFieldDef(schema Schema, parentType *Object, fieldName string) *FieldDefi
return parentType.Fields()[fieldName]
}

func GetFieldDef(schema Schema, parentType *Object, fieldName string) *FieldDefinition {
return getFieldDef(schema, parentType, fieldName)
}

// contains field information that will be placed in an ordered slice
type orderedField struct {
responseName string
Expand Down
10 changes: 9 additions & 1 deletion values.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ func valueFromAST(valueAST ast.Value, ttype Input, variables map[string]interfac
values := []interface{}{}
if valueAST, ok := valueAST.(*ast.ListValue); ok {
for _, itemAST := range valueAST.Values {
values = append(values, valueFromAST(itemAST, ttype.OfType, variables))
val := valueFromAST(itemAST, ttype.OfType, variables)
if _, ok := val.(nullValue); ok { // Null value
val = nil
}
values = append(values, val)
}
return values
}
Expand Down Expand Up @@ -443,6 +447,10 @@ func valueFromAST(valueAST ast.Value, ttype Input, variables map[string]interfac
return nil
}

func ValueFromAST(valueAST ast.Value, ttype Input, variables map[string]interface{}) interface{} {
return valueFromAST(valueAST, ttype, variables)
}

func invariant(condition bool, message string) error {
if !condition {
return gqlerrors.NewFormattedError(message)
Expand Down

0 comments on commit 1db5193

Please sign in to comment.