diff --git a/examples/modify-context/main.go b/examples/modify-context/main.go index 0432b3ba..a2b1cba4 100644 --- a/examples/modify-context/main.go +++ b/examples/modify-context/main.go @@ -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) diff --git a/executor_resolve_test.go b/executor_resolve_test.go index 7430cd86..6f8f8ab5 100644 --- a/executor_resolve_test.go +++ b/executor_resolve_test.go @@ -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)) @@ -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)) diff --git a/graphql.go b/graphql.go index 2b1f6a29..c4b824e3 100644 --- a/graphql.go +++ b/graphql.go @@ -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{} @@ -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,