Skip to content

Commit 861ce4f

Browse files
committed
fixing tests
1 parent 3b7d880 commit 861ce4f

4 files changed

Lines changed: 52 additions & 38 deletions

File tree

‎src/main/java/graphql/language/FieldDefinition.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public Description getDescription() {
5151
}
5252

5353
public List<InputValueDefinition> getInputValueDefinitions() {
54-
return inputValueDefinitions;
54+
return new ArrayList<>(inputValueDefinitions);
5555
}
5656

5757
@Override
5858
public List<Directive> getDirectives() {
59-
return directives;
59+
return new ArrayList<>(directives);
6060
}
6161

6262
@Override

‎src/main/java/graphql/language/ObjectTypeExtensionDefinition.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,31 @@ public Builder implementz(List<Type> implementz) {
9292
return this;
9393
}
9494

95+
public Builder implementz(Type implementz) {
96+
this.implementz.add(implementz);
97+
return this;
98+
}
99+
95100
public Builder directives(List<Directive> directives) {
96101
this.directives = directives;
97102
return this;
98103
}
99104

105+
public Builder directive(Directive directive) {
106+
this.directives.add(directive);
107+
return this;
108+
}
109+
100110
public Builder fieldDefinitions(List<FieldDefinition> fieldDefinitions) {
101111
this.fieldDefinitions = fieldDefinitions;
102112
return this;
103113
}
104114

115+
public Builder fieldDefinition(FieldDefinition fieldDefinition) {
116+
this.fieldDefinitions.add(fieldDefinition);
117+
return this;
118+
}
119+
105120
public ObjectTypeExtensionDefinition build() {
106121
ObjectTypeExtensionDefinition objectTypeDefinition = new ObjectTypeExtensionDefinition(name,
107122
implementz,

‎src/main/java/graphql/language/UnionTypeDefinition.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ public Builder directives(List<Directive> directives) {
147147
return this;
148148
}
149149

150+
public Builder directive(Directive directive) {
151+
this.directives.add(directive);
152+
return this;
153+
}
154+
150155
public Builder memberTypes(List<Type> memberTypes) {
151156
this.memberTypes = memberTypes;
152157
return this;

‎src/test/groovy/graphql/parser/IDLParserTest.groovy‎

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,18 @@ union UnionName @d1 @d2 = Type1 | Type2
241241
"""
242242

243243
and: "expected schema"
244-
def schema = new UnionTypeDefinition("UnionName")
245-
schema.getDirectives().add(new Directive("d1"))
246-
schema.getDirectives().add(new Directive("d2"))
247-
schema.getMemberTypes().add(new TypeName("Type1"))
248-
schema.getMemberTypes().add(new TypeName("Type2"))
244+
def schema = UnionTypeDefinition.newUnionTypeDefinition().name("UnionName")
245+
schema.directive(new Directive("d1"))
246+
schema.directive(new Directive("d2"))
247+
schema.memberType(new TypeName("Type1"))
248+
schema.memberType(new TypeName("Type2"))
249249

250250
when:
251251
def document = new Parser().parseDocument(input)
252252

253253
then:
254254
document.definitions.size() == 1
255-
isEqual(document.definitions[0], schema)
255+
isEqual(document.definitions[0], schema.build())
256256
}
257257

258258
def "input object schema"() {
@@ -311,7 +311,7 @@ schema @d1 @d2 {
311311

312312
then:
313313
document.definitions.size() == 1
314-
isEqual(document.definitions[0], schema)
314+
isEqual(document.definitions[0], schema.build())
315315
}
316316

317317
def "extend schema"() {
@@ -325,33 +325,31 @@ withArgs(arg1:[Number]=[1] arg2:String @secondArg(cool:true)): Function
325325
"""
326326

327327
and: "expected schema"
328-
def schema = new ObjectTypeExtensionDefinition("ExtendType")
329-
schema.getImplements().add(new TypeName("Impl3"))
330-
schema.getDirectives()
331-
.add(new Directive("extendDirective", [new Argument("a1", new VariableReference("v1"))]))
332-
schema.getFieldDefinitions()
333-
.add(new FieldDefinition("one", new TypeName("Int")))
334-
def two = new FieldDefinition("two", new TypeName("Int"))
335-
two.getDirectives().add(new Directive("second"))
336-
schema.getFieldDefinitions().add(two)
337-
338-
def withArgs = new FieldDefinition("withArgs", new TypeName("Function"))
339-
withArgs.getInputValueDefinitions()
340-
.add(new InputValueDefinition("arg1",
328+
def schema = ObjectTypeExtensionDefinition.newObjectTypeExtensionDefinition().name("ExtendType")
329+
schema.implementz(new TypeName("Impl3"))
330+
schema.directive(new Directive("extendDirective", [new Argument("a1", new VariableReference("v1"))]))
331+
schema.fieldDefinition(new FieldDefinition("one", new TypeName("Int")))
332+
333+
def two = FieldDefinition.newFieldDefintion().name("two").type(new TypeName("Int"))
334+
two.directive(new Directive("second"))
335+
schema.fieldDefinition(two.build())
336+
337+
def withArgs = FieldDefinition.newFieldDefintion().name("withArgs").type(new TypeName("Function"))
338+
withArgs.inputValueDefinition(new InputValueDefinition("arg1",
341339
new ListType(new TypeName("Number")),
342340
new ArrayValue([new IntValue(1)])))
343-
def arg2 = new InputValueDefinition("arg2", new TypeName("String"))
344-
arg2.getDirectives()
345-
.add(new Directive("secondArg", [new Argument("cool", new BooleanValue(true))]))
346-
withArgs.getInputValueDefinitions().add(arg2)
347-
schema.getFieldDefinitions().add(withArgs)
341+
342+
def arg2 = InputValueDefinition.newInputValueDefinition().name("arg2").type(new TypeName("String"))
343+
arg2.directive(new Directive("secondArg", [new Argument("cool", new BooleanValue(true))]))
344+
withArgs.inputValueDefinition(arg2.build())
345+
schema.fieldDefinition(withArgs.build())
348346

349347
when:
350348
def document = new Parser().parseDocument(input)
351349

352350
then:
353351
document.definitions.size() == 1
354-
isEqual(document.definitions[0], schema)
352+
isEqual(document.definitions[0], schema.build())
355353
}
356354

357355
def "directive schema"() {
@@ -361,22 +359,18 @@ directive @DirectiveName(arg1:String arg2:Int=23) on FIELD | QUERY
361359
"""
362360

363361
and: "expected schema"
364-
def schema = new DirectiveDefinition("DirectiveName")
365-
schema.getInputValueDefinitions()
366-
.add(new InputValueDefinition("arg1", new TypeName("String")))
367-
schema.getInputValueDefinitions()
368-
.add(new InputValueDefinition("arg2", new TypeName("Int"), new IntValue(23)))
369-
schema.getDirectiveLocations()
370-
.add(new DirectiveLocation("FIELD"))
371-
schema.getDirectiveLocations()
372-
.add(new DirectiveLocation("QUERY"))
362+
def schema = DirectiveDefinition.newDirectiveDefinition().name("DirectiveName")
363+
schema.inputValueDefinition(new InputValueDefinition("arg1", new TypeName("String")))
364+
schema.inputValueDefinition(new InputValueDefinition("arg2", new TypeName("Int"), new IntValue(23)))
365+
schema.directiveLocation(new DirectiveLocation("FIELD"))
366+
schema.directiveLocation(new DirectiveLocation("QUERY"))
373367

374368
when:
375369
def document = new Parser().parseDocument(input)
376370

377371
then:
378372
document.definitions.size() == 1
379-
isEqual(document.definitions[0], schema)
373+
isEqual(document.definitions[0], schema.build())
380374
}
381375

382376

0 commit comments

Comments
 (0)