|
44 | 44 | assert_equal schema_string, document.to_query_string |
45 | 45 | end |
46 | 46 |
|
| 47 | + describe "implements" do |
| 48 | + it "parses when there are no interfaces" do |
| 49 | + schema = " |
| 50 | + type A { |
| 51 | + a: String |
| 52 | + } |
| 53 | + " |
| 54 | + |
| 55 | + document = subject.parse(schema) |
| 56 | + |
| 57 | + assert_equal [], document.definitions[0].interfaces.map(&:name) |
| 58 | + end |
| 59 | + |
| 60 | + it "parses with leading ampersand" do |
| 61 | + schema = " |
| 62 | + type A implements & B { |
| 63 | + a: String |
| 64 | + } |
| 65 | + " |
| 66 | + |
| 67 | + document = subject.parse(schema) |
| 68 | + |
| 69 | + assert_equal ["B"], document.definitions[0].interfaces.map(&:name) |
| 70 | + end |
| 71 | + |
| 72 | + it "parses with leading ampersand and multiple interfaces" do |
| 73 | + schema = " |
| 74 | + type A implements & B & C { |
| 75 | + a: String |
| 76 | + } |
| 77 | + " |
| 78 | + |
| 79 | + document = subject.parse(schema) |
| 80 | + |
| 81 | + assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name) |
| 82 | + end |
| 83 | + |
| 84 | + it "parses without leading ampersand" do |
| 85 | + schema = " |
| 86 | + type A implements B { |
| 87 | + a: String |
| 88 | + } |
| 89 | + " |
| 90 | + |
| 91 | + document = subject.parse(schema) |
| 92 | + |
| 93 | + assert_equal ["B"], document.definitions[0].interfaces.map(&:name) |
| 94 | + end |
| 95 | + |
| 96 | + it "parses without leading ampersand and multiple interfaces" do |
| 97 | + schema = " |
| 98 | + type A implements B & C { |
| 99 | + a: String |
| 100 | + } |
| 101 | + " |
| 102 | + |
| 103 | + document = subject.parse(schema) |
| 104 | + |
| 105 | + assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name) |
| 106 | + end |
| 107 | + |
| 108 | + it "supports the old way of parsing multiple interfaces for backwards compatibility" do |
| 109 | + schema = " |
| 110 | + type A implements B, C { |
| 111 | + a: String |
| 112 | + } |
| 113 | + " |
| 114 | + |
| 115 | + document = subject.parse(schema) |
| 116 | + |
| 117 | + assert_equal ["B", "C"], document.definitions[0].interfaces.map(&:name) |
| 118 | + end |
| 119 | + end |
| 120 | + |
47 | 121 | describe ".parse_file" do |
48 | 122 | it "assigns filename to all nodes" do |
49 | 123 | example_filename = "spec/support/parser/filename_example.graphql" |
|
0 commit comments