Skip to content

Commit bca2f15

Browse files
committed
fix: issue #65: Deprecate Params.RootValue in favor of a Params.Root that is an interface{}
1 parent 8a92e97 commit bca2f15

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

examples/modify-context/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func main() {
6464
result := graphql.Do(graphql.Params{
6565
Context: ctx,
6666
RequestString: "{ users { id } }",
67-
RootObject: rootObject,
67+
Root: rootObject,
6868
Schema: schema,
6969
})
7070
b, err := json.Marshal(result)

executor_resolve_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestExecutesResolveFunction_DefaultFunctionAccessesProperties(t *testing.T)
3737
result := graphql.Do(graphql.Params{
3838
Schema: schema,
3939
RequestString: `{ test }`,
40-
RootObject: source,
40+
Root: source,
4141
})
4242
if !reflect.DeepEqual(expected, result.Data) {
4343
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result.Data))
@@ -60,7 +60,7 @@ func TestExecutesResolveFunction_DefaultFunctionCallsMethods(t *testing.T) {
6060
result := graphql.Do(graphql.Params{
6161
Schema: schema,
6262
RequestString: `{ test }`,
63-
RootObject: source,
63+
Root: source,
6464
})
6565
if !reflect.DeepEqual(expected, result.Data) {
6666
t.Fatalf("Unexpected result, Diff: %v", testutil.Diff(expected, result.Data))

graphql.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ type Params struct {
1717

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

24+
// The value provided as the first argument to resolver functions on the top
25+
// level type (e.g. the query object type).
26+
Root interface{}
27+
2228
// A mapping of variable name to runtime value to use for all variables
2329
// defined in the requestString.
2430
VariableValues map[string]interface{}
@@ -105,9 +111,14 @@ func Do(p Params) *Result {
105111
}
106112
}
107113

114+
root := p.Root
115+
if root == nil {
116+
root = p.RootObject
117+
}
118+
108119
return Execute(ExecuteParams{
109120
Schema: p.Schema,
110-
Root: p.RootObject,
121+
Root: root,
111122
AST: AST,
112123
OperationName: p.OperationName,
113124
Args: p.VariableValues,

0 commit comments

Comments
 (0)