Skip to content

Commit

Permalink
fix optional input fields (fixes #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Nov 20, 2016
1 parent a15deed commit 4838c6f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func TestMutation(t *testing.T) {
Variables: map[string]interface{}{
"ep": "JEDI",
"review": map[string]interface{}{
"stars": float64(5),
"stars": 5,
"commentary": "This is a great movie!",
},
},
Expand All @@ -778,6 +778,32 @@ func TestMutation(t *testing.T) {
`,
},

{
Schema: starwarsSchema,
Query: `
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
createReview(episode: $ep, review: $review) {
stars
commentary
}
}
`,
Variables: map[string]interface{}{
"ep": "EMPIRE",
"review": map[string]interface{}{
"stars": float64(4),
},
},
ExpectedResult: `
{
"createReview": {
"stars": 4,
"commentary": null
}
}
`,
},

{
Schema: starwarsSchema,
Query: `
Expand Down
3 changes: 3 additions & 0 deletions internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ func coerceMap(r *request, io *common.InputMap, m map[string]interface{}) (map[s
for _, iv := range io.Fields {
value, ok := m[iv.Name]
if !ok {
if _, nonNull := unwrapNonNull(iv.Type); !nonNull {
continue
}
if iv.Default == nil {
return nil, errors.Errorf("missing %q", iv.Name)
}
Expand Down

0 comments on commit 4838c6f

Please sign in to comment.