Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom map types in resolvers #440

Merged
merged 3 commits into from
Mar 10, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds regression test for #439.
  • Loading branch information
atombender committed Feb 4, 2019
commit db6bc15feab150eae1f2bde7e1556ce42847b041
56 changes: 56 additions & 0 deletions executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,62 @@ func TestMergesParallelFragments(t *testing.T) {
}
}

type CustomMap map[string]interface{}

func TestCustomMapType(t *testing.T) {
query := `
query Example { data { a } }
`
data := CustomMap{
"a": "1",
"b": "2",
}
schema, err := graphql.NewSchema(graphql.SchemaConfig{
Query: graphql.NewObject(graphql.ObjectConfig{
Name: "RootQuery",
Fields: graphql.Fields{
"data": &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "Data",
Fields: graphql.Fields{
"a": &graphql.Field{
Type: graphql.String,
},
"b": &graphql.Field{
Type: graphql.String,
},
},
}),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
return data, nil
},
},
},
}),
})
if err != nil {
t.Fatalf("Error in schema %v", err.Error())
}

result := testutil.TestExecute(t, graphql.ExecuteParams{
Schema: schema,
Root: data,
AST: testutil.TestParse(t, query),
})
if len(result.Errors) > 0 {
t.Fatalf("wrong result, unexpected errors: %v", result.Errors)
}

expected := map[string]interface{}{
"data": map[string]interface{}{
"a": "1",
},
}
if !reflect.DeepEqual(result.Data, expected) {
t.Fatalf("Expected context.key to equal %v, got %v", expected, result.Data)
}
}

func TestThreadsSourceCorrectly(t *testing.T) {

query := `
Expand Down