-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #25 -- validate the parameters/args used in directives agai…
…nst the variables defined in the operation (and tests)
- Loading branch information
Showing
4 changed files
with
203 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package tests.operations; | ||
|
||
import buddy.*; | ||
using buddy.Should; | ||
|
||
class VerifyDirectives extends BuddySuite | ||
{ | ||
|
||
public static inline var common_gql = ' | ||
|
||
# Creates typedefs for all schema types | ||
|
||
type FooData { | ||
foo_id:ID! | ||
} | ||
|
||
type BarData { | ||
bar_id:ID! | ||
} | ||
|
||
union SomeData = FooData | BarData | ||
|
||
type OuterData { | ||
id:ID! | ||
title:String! | ||
description:String | ||
foo_or_bar_data: SomeData! | ||
} | ||
|
||
type Query { | ||
get_content_by_id: OuterData | ||
} | ||
|
||
'; | ||
|
||
public function new() { | ||
describe("VerifyDirectives:", { | ||
|
||
it('should validate these directives without error', { | ||
var parser = new graphql.parser.Parser(common_gql+' | ||
|
||
fragment InnerFrag on OuterData { | ||
foo_or_bar_data @include(if: $$with_data) { | ||
...on FooData { | ||
common_id: foo_id | ||
} | ||
...on BarData { | ||
common_id: bar_id | ||
} | ||
} | ||
} | ||
|
||
query GetContentsByID($$id: ID, $$with_data: Boolean=false) { | ||
get_content_by_id(id: $$id) { | ||
title | ||
description | ||
foo_or_bar_data @include(if: $$with_data) { | ||
...on FooData { | ||
foo_id | ||
} | ||
} | ||
...InnerFrag | ||
} | ||
} | ||
|
||
'); | ||
|
||
var result = graphql.HaxeGenerator.parse(parser.document).stdout; | ||
result.should.contain("typedef OP_GetContentsByID_Result"); | ||
}); | ||
|
||
|
||
|
||
it('should throw on a query directive typo', { | ||
var parser = new graphql.parser.Parser(common_gql+' | ||
|
||
fragment InnerFrag on OuterData { | ||
foo_or_bar_data @include(if: $$with_data) { | ||
...on FooData { | ||
common_id: foo_id | ||
} | ||
...on BarData { | ||
common_id: bar_id | ||
} | ||
} | ||
} | ||
|
||
query GetContentsByID($$id: ID, $$with_data: Boolean=false) { | ||
get_content_by_id(id: $$id) { | ||
title | ||
description | ||
foo_or_bar_data @include(if: $$with_a_typo) { | ||
...on FooData { | ||
foo_id | ||
} | ||
} | ||
...InnerFrag | ||
} | ||
} | ||
|
||
'); | ||
|
||
var err = graphql.HaxeGenerator.parse.bind(parser.document).should.throwType(String); | ||
err.should.contain("operation GetContentsByID is expecting parameter with_a_typo"); | ||
}); | ||
|
||
|
||
it('should throw on a fragment directive typo', { | ||
var parser = new graphql.parser.Parser(common_gql+' | ||
|
||
fragment InnerFrag on OuterData { | ||
foo_or_bar_data @include(if: $$with_frag_typo) { | ||
...on FooData { | ||
common_id: foo_id | ||
} | ||
...on BarData { | ||
common_id: bar_id | ||
} | ||
} | ||
} | ||
|
||
query GetContentsByID($$id: ID, $$with_data: Boolean=false) { | ||
get_content_by_id(id: $$id) { | ||
title | ||
description | ||
foo_or_bar_data @include(if: $$with_data) { | ||
...on FooData { | ||
foo_id | ||
} | ||
} | ||
...InnerFrag | ||
} | ||
} | ||
|
||
'); | ||
|
||
var err = graphql.HaxeGenerator.parse.bind(parser.document).should.throwType(String); | ||
err.should.contain("operation GetContentsByID is expecting parameter with_frag_typo"); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters