Skip to content

Commit

Permalink
fix: issue #65: Deprecate Params.RootValue in favor of a Params.Root …
Browse files Browse the repository at this point in the history
…that is an interface{}
  • Loading branch information
chirino committed Aug 24, 2021
1 parent 8a92e97 commit bca2f15
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/modify-context/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
result := graphql.Do(graphql.Params{
Context: ctx,
RequestString: "{ users { id } }",
RootObject: rootObject,
Root: rootObject,
Schema: schema,
})
b, err := json.Marshal(result)
Expand Down
4 changes: 2 additions & 2 deletions executor_resolve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestExecutesResolveFunction_DefaultFunctionAccessesProperties(t *testing.T)
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: `{ test }`,
RootObject: source,
Root: source,
})
if !reflect.DeepEqual(expected, result.Data) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result.Data))
Expand All @@ -60,7 +60,7 @@ func TestExecutesResolveFunction_DefaultFunctionCallsMethods(t *testing.T) {
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: `{ test }`,
RootObject: source,
Root: source,
})
if !reflect.DeepEqual(expected, result.Data) {
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result.Data))
Expand Down
13 changes: 12 additions & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ type Params struct {

// The value provided as the first argument to resolver functions on the top
// level type (e.g. the query object type).
//
// Deprecated: use the Root field instead.
RootObject map[string]interface{}

// The value provided as the first argument to resolver functions on the top
// level type (e.g. the query object type).
Root interface{}

// A mapping of variable name to runtime value to use for all variables
// defined in the requestString.
VariableValues map[string]interface{}
Expand Down Expand Up @@ -105,9 +111,14 @@ func Do(p Params) *Result {
}
}

root := p.Root
if root == nil {
root = p.RootObject
}

return Execute(ExecuteParams{
Schema: p.Schema,
Root: p.RootObject,
Root: root,
AST: AST,
OperationName: p.OperationName,
Args: p.VariableValues,
Expand Down

0 comments on commit bca2f15

Please sign in to comment.