Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1b120b2
1764: Interfaces implementing interfaces working with partial validation
felipe-gdr Apr 26, 2020
5dca065
1764: Assert error messages
felipe-gdr Apr 27, 2020
ecb52d3
1764: Check if interface is implementing itself
felipe-gdr Apr 27, 2020
ea740ef
1764: Fix bug with circular dependency
felipe-gdr Apr 28, 2020
3dfdab1
1764: Use String.join instead of realying on Collection#toString
felipe-gdr Apr 28, 2020
ae71b4a
1764: Better test assertions
felipe-gdr Apr 29, 2020
81b1b26
1764: Add tests for transitive implementation declared in interface e…
felipe-gdr Apr 29, 2020
0039150
1764: Simplify implementation of transitive validation
felipe-gdr Apr 29, 2020
465e4a9
1764: Fix transitive implementation declared in extension interface bug
felipe-gdr May 4, 2020
4015f0d
1764: Add tests for field and arguments check
felipe-gdr May 17, 2020
cfe170e
1764: Create integration test
felipe-gdr May 20, 2020
04cfbe7
1764: PR feedback
felipe-gdr May 19, 2020
39dc3d4
1764: Improve query integration test and add introspection query test
felipe-gdr May 21, 2020
7656983
improve tests
andimarek May 21, 2020
d04a6ec
add Interfaces to GraphQLInterfaceType
andimarek May 22, 2020
b785a5b
test programmatically GraphQLInterfaceType
andimarek May 22, 2020
2792f3a
transitively declaring all interfaces
andimarek May 22, 2020
2415050
astprinter handles interfaces in interfaces
andimarek May 22, 2020
e7a5d84
add schema printer test
andimarek May 22, 2020
420481f
1764: Implemente interface implement interface validation in SchemaVa…
felipe-gdr May 24, 2020
08d4bb9
add test for interface extensions
andimarek May 24, 2020
7601889
Merge branch 'master' into 1764_allow-interfaces-to-implement-other-i…
andimarek May 24, 2020
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
7 changes: 4 additions & 3 deletions src/main/antlr/GraphqlSDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ argumentsDefinition : '(' inputValueDefinition+ ')';

inputValueDefinition : description? name ':' type defaultValue? directives?;

interfaceTypeDefinition : description? INTERFACE name directives? fieldsDefinition?;
interfaceTypeDefinition : description? INTERFACE name implementsInterfaces? directives? fieldsDefinition?;

interfaceTypeExtensionDefinition :
EXTEND INTERFACE name directives? extensionFieldsDefinition |
EXTEND INTERFACE name directives emptyParentheses?
EXTEND INTERFACE name implementsInterfaces? directives? extensionFieldsDefinition |
EXTEND INTERFACE name implementsInterfaces? directives emptyParentheses? |
EXTEND INTERFACE name implementsInterfaces
;


Expand Down
3 changes: 3 additions & 0 deletions src/main/java/graphql/introspection/Introspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ private static String print(Object value, GraphQLInputType type) {
if (type instanceof GraphQLObjectType) {
return ((GraphQLObjectType) type).getInterfaces();
}
if (type instanceof GraphQLInterfaceType) {
return ((GraphQLInterfaceType) type).getInterfaces();
}
return null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import graphql.language.OperationTypeDefinition;
import graphql.language.ScalarTypeDefinition;
import graphql.language.SchemaDefinition;
import graphql.language.SourceLocation;
import graphql.language.StringValue;
import graphql.language.Type;
import graphql.language.TypeDefinition;
import graphql.language.TypeName;
import graphql.language.UnionTypeDefinition;
import graphql.language.Value;
import graphql.schema.idl.ScalarInfo;
import graphql.util.FpKit;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -186,6 +186,14 @@ InterfaceTypeDefinition createInterface(Map<String, Object> input) {

InterfaceTypeDefinition.Builder interfaceTypeDefinition = InterfaceTypeDefinition.newInterfaceTypeDefinition().name((String) input.get("name"));
interfaceTypeDefinition.description(toDescription(input));
if (input.containsKey("interfaces") && input.get("interfaces") != null) {
interfaceTypeDefinition.implementz(
FpKit.map(
(List<Map<String, Object>>) input.get("interfaces"),
this::createTypeIndirection
)
);
}
List<Map<String, Object>> fields = (List<Map<String, Object>>) input.get("fields");
interfaceTypeDefinition.definitions(createFields(fields));

Expand Down
1 change: 1 addition & 0 deletions src/main/java/graphql/language/AstPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private NodePrinter<InterfaceTypeDefinition> interfaceTypeDefinition() {
out.printf("%s", spaced(
"interface",
node.getName(),
wrap("implements ", join(node.getImplements(), " & "), ""),
directives(node.getDirectives()),
block(node.getFieldDefinitions())
)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/graphql/language/AstSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public TraversalControl visitObjectTypeDefinition(ObjectTypeDefinition node, Tra
public TraversalControl visitInterfaceTypeDefinition(InterfaceTypeDefinition node, TraverserContext<Node> context) {
InterfaceTypeDefinition changedNode = node.transform(builder -> {
builder.directives(sort(node.getDirectives(), comparing(Directive::getName)));
builder.implementz(sort(node.getImplements(), comparingTypes()));
builder.definitions(sort(node.getFieldDefinitions(), comparing(FieldDefinition::getName)));
});
return changeNode(context, changedNode);
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/graphql/language/ImplementingTypeDefinition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package graphql.language;


import graphql.PublicApi;

import java.util.List;

/**
* A {@link TypeDefinition} that might implement interfaces
*
* @param <T>
*/
@PublicApi
public interface ImplementingTypeDefinition<T extends TypeDefinition> extends TypeDefinition<T> {

List<Type> getImplements();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not great name, but not in scope to change it here.


List<FieldDefinition> getFieldDefinitions();
}
32 changes: 30 additions & 2 deletions src/main/java/graphql/language/InterfaceTypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@
import static java.util.Collections.emptyMap;

@PublicApi
public class InterfaceTypeDefinition extends AbstractDescribedNode<InterfaceTypeDefinition> implements TypeDefinition<InterfaceTypeDefinition>, DirectivesContainer<InterfaceTypeDefinition>, NamedNode<InterfaceTypeDefinition> {
public class InterfaceTypeDefinition extends AbstractDescribedNode<InterfaceTypeDefinition> implements ImplementingTypeDefinition<InterfaceTypeDefinition>, DirectivesContainer<InterfaceTypeDefinition>, NamedNode<InterfaceTypeDefinition> {

private final String name;
private final List<Type> implementz;
private final List<FieldDefinition> definitions;
private final List<Directive> directives;

public static final String CHILD_IMPLEMENTZ = "implementz";
public static final String CHILD_DEFINITIONS = "definitions";
public static final String CHILD_DIRECTIVES = "directives";

@Internal
protected InterfaceTypeDefinition(String name,
List<Type> implementz,
List<FieldDefinition> definitions,
List<Directive> directives,
Description description,
Expand All @@ -37,6 +40,7 @@ protected InterfaceTypeDefinition(String name,
Map<String, String> additionalData) {
super(sourceLocation, comments, ignoredChars, additionalData, description);
this.name = name;
this.implementz = implementz;
this.definitions = definitions;
this.directives = directives;
}
Expand All @@ -47,9 +51,15 @@ protected InterfaceTypeDefinition(String name,
* @param name of the interface
*/
public InterfaceTypeDefinition(String name) {
this(name, new ArrayList<>(), new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
this(name, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
}

@Override
public List<Type> getImplements() {
return new ArrayList<>(implementz);
}

@Override
public List<FieldDefinition> getFieldDefinitions() {
return new ArrayList<>(definitions);
}
Expand All @@ -67,6 +77,7 @@ public String getName() {
@Override
public List<Node> getChildren() {
List<Node> result = new ArrayList<>();
result.addAll(implementz);
result.addAll(definitions);
result.addAll(directives);
return result;
Expand All @@ -75,6 +86,7 @@ public List<Node> getChildren() {
@Override
public NodeChildrenContainer getNamedChildren() {
return newNodeChildrenContainer()
.children(CHILD_IMPLEMENTZ, implementz)
.children(CHILD_DEFINITIONS, definitions)
.children(CHILD_DIRECTIVES, directives)
.build();
Expand All @@ -83,6 +95,7 @@ public NodeChildrenContainer getNamedChildren() {
@Override
public InterfaceTypeDefinition withNewChildren(NodeChildrenContainer newChildren) {
return transform(builder -> builder
.implementz(newChildren.getChildren(CHILD_IMPLEMENTZ))
.definitions(newChildren.getChildren(CHILD_DEFINITIONS))
.directives(newChildren.getChildren(CHILD_DIRECTIVES))
);
Expand All @@ -105,6 +118,7 @@ public boolean isEqualTo(Node o) {
@Override
public InterfaceTypeDefinition deepCopy() {
return new InterfaceTypeDefinition(name,
deepCopy(implementz),
deepCopy(definitions),
deepCopy(directives),
description,
Expand All @@ -118,6 +132,7 @@ public InterfaceTypeDefinition deepCopy() {
public String toString() {
return "InterfaceTypeDefinition{" +
"name='" + name + '\'' +
", implements=" + implementz +
", fieldDefinitions=" + definitions +
", directives=" + directives +
'}';
Expand All @@ -144,6 +159,7 @@ public static final class Builder implements NodeBuilder {
private List<Comment> comments = new ArrayList<>();
private String name;
private Description description;
private List<Type> implementz = new ArrayList<>();
private List<FieldDefinition> definitions = new ArrayList<>();
private List<Directive> directives = new ArrayList<>();
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
Expand Down Expand Up @@ -185,6 +201,17 @@ public Builder description(Description description) {
return this;
}

public Builder implementz(List<Type> implementz) {
this.implementz = implementz;
return this;
}

public Builder implementz(Type implement) {
this.implementz.add(implement);
return this;
}


public Builder definitions(List<FieldDefinition> definitions) {
this.definitions = definitions;
return this;
Expand Down Expand Up @@ -223,6 +250,7 @@ public Builder additionalData(String key, String value) {

public InterfaceTypeDefinition build() {
return new InterfaceTypeDefinition(name,
implementz,
definitions,
directives,
description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ public class InterfaceTypeExtensionDefinition extends InterfaceTypeDefinition {

@Internal
protected InterfaceTypeExtensionDefinition(String name,
List<Type> implementz,
List<FieldDefinition> definitions,
List<Directive> directives,
Description description,
SourceLocation sourceLocation,
List<Comment> comments,
IgnoredChars ignoredChars,
Map<String, String> additionalData) {
super(name, definitions, directives, description, sourceLocation, comments, ignoredChars, additionalData);
super(name, implementz, definitions, directives, description, sourceLocation, comments, ignoredChars, additionalData);
}

@Override
public InterfaceTypeExtensionDefinition deepCopy() {
return new InterfaceTypeExtensionDefinition(getName(),
getImplements(),
deepCopy(getFieldDefinitions()),
deepCopy(getDirectives()),
getDescription(),
Expand Down Expand Up @@ -63,6 +65,7 @@ public static final class Builder implements NodeBuilder {
private List<Comment> comments = new ArrayList<>();
private String name;
private Description description;
private List<Type> implementz = new ArrayList<>();
private List<FieldDefinition> definitions = new ArrayList<>();
private List<Directive> directives = new ArrayList<>();
private IgnoredChars ignoredChars = IgnoredChars.EMPTY;
Expand All @@ -77,6 +80,7 @@ private Builder(InterfaceTypeExtensionDefinition existing) {
this.name = existing.getName();
this.description = existing.getDescription();
this.directives = existing.getDirectives();
this.implementz = existing.getImplements();
this.definitions = existing.getFieldDefinitions();
this.ignoredChars = existing.getIgnoredChars();
this.additionalData = new LinkedHashMap<>(existing.getAdditionalData());
Expand All @@ -102,6 +106,16 @@ public Builder description(Description description) {
return this;
}

public Builder implementz(List<Type> implementz) {
this.implementz = implementz;
return this;
}

public Builder implementz(Type implementz) {
this.implementz.add(implementz);
return this;
}

public Builder definitions(List<FieldDefinition> definitions) {
this.definitions = definitions;
return this;
Expand Down Expand Up @@ -130,6 +144,7 @@ public Builder additionalData(String key, String value) {

public InterfaceTypeExtensionDefinition build() {
return new InterfaceTypeExtensionDefinition(name,
implementz,
definitions,
directives,
description,
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/graphql/language/ObjectTypeDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static java.util.Collections.emptyMap;

@PublicApi
public class ObjectTypeDefinition extends AbstractDescribedNode<ObjectTypeDefinition> implements TypeDefinition<ObjectTypeDefinition>, DirectivesContainer<ObjectTypeDefinition>, NamedNode<ObjectTypeDefinition> {
public class ObjectTypeDefinition extends AbstractDescribedNode<ObjectTypeDefinition> implements ImplementingTypeDefinition<ObjectTypeDefinition>, DirectivesContainer<ObjectTypeDefinition>, NamedNode<ObjectTypeDefinition> {
private final String name;
private final List<Type> implementz;
private final List<Directive> directives;
Expand Down Expand Up @@ -53,6 +53,7 @@ public ObjectTypeDefinition(String name) {
this(name, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, new ArrayList<>(), IgnoredChars.EMPTY, emptyMap());
}

@Override
public List<Type> getImplements() {
return new ArrayList<>(implementz);
}
Expand All @@ -62,6 +63,7 @@ public List<Directive> getDirectives() {
return new ArrayList<>(directives);
}

@Override
public List<FieldDefinition> getFieldDefinitions() {
return new ArrayList<>(fieldDefinitions);
}
Expand Down
32 changes: 20 additions & 12 deletions src/main/java/graphql/parser/GraphqlAntlrToLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import graphql.language.VariableReference;
import graphql.parser.antlr.GraphqlLexer;
import graphql.parser.antlr.GraphqlParser;
import graphql.util.FpKit;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
Expand Down Expand Up @@ -432,12 +433,7 @@ protected ObjectTypeDefinition createObjectTypeDefinition(GraphqlParser.ObjectTy
def.description(newDescription(ctx.description()));
def.directives(createDirectives(ctx.directives()));
GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext = ctx.implementsInterfaces();
List<Type> implementz = new ArrayList<>();
while (implementsInterfacesContext != null) {
List<TypeName> typeNames = implementsInterfacesContext.typeName().stream().map(this::createTypeName).collect(toList());
implementz.addAll(0, typeNames);
implementsInterfacesContext = implementsInterfacesContext.implementsInterfaces();
}
List<Type> implementz = getImplementz(implementsInterfacesContext);
def.implementz(implementz);
if (ctx.fieldsDefinition() != null) {
def.fieldDefinitions(createFieldDefinitions(ctx.fieldsDefinition()));
Expand All @@ -451,12 +447,7 @@ protected ObjectTypeExtensionDefinition createObjectTypeExtensionDefinition(Grap
addCommonData(def, ctx);
def.directives(createDirectives(ctx.directives()));
GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext = ctx.implementsInterfaces();
List<Type> implementz = new ArrayList<>();
while (implementsInterfacesContext != null) {
List<TypeName> typeNames = implementsInterfacesContext.typeName().stream().map(this::createTypeName).collect(toList());
implementz.addAll(0, typeNames);
implementsInterfacesContext = implementsInterfacesContext.implementsInterfaces();
}
List<Type> implementz = getImplementz(implementsInterfacesContext);
def.implementz(implementz);
if (ctx.extensionFieldsDefinition() != null) {
def.fieldDefinitions(createFieldDefinitions(ctx.extensionFieldsDefinition()));
Expand Down Expand Up @@ -516,6 +507,9 @@ protected InterfaceTypeDefinition createInterfaceTypeDefinition(GraphqlParser.In
addCommonData(def, ctx);
def.description(newDescription(ctx.description()));
def.directives(createDirectives(ctx.directives()));
GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext = ctx.implementsInterfaces();
List<Type> implementz = getImplementz(implementsInterfacesContext);
def.implementz(implementz);
def.definitions(createFieldDefinitions(ctx.fieldsDefinition()));
return def.build();
}
Expand All @@ -525,6 +519,9 @@ protected InterfaceTypeExtensionDefinition createInterfaceTypeExtensionDefinitio
def.name(ctx.name().getText());
addCommonData(def, ctx);
def.directives(createDirectives(ctx.directives()));
GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext = ctx.implementsInterfaces();
List<Type> implementz = getImplementz(implementsInterfacesContext);
def.implementz(implementz);
def.definitions(createFieldDefinitions(ctx.extensionFieldsDefinition()));
return def.build();
}
Expand Down Expand Up @@ -881,4 +878,15 @@ protected List<Comment> getCommentOnChannel(List<Token> refChannel) {
return comments;
}


private List<Type> getImplementz(GraphqlParser.ImplementsInterfacesContext implementsInterfacesContext) {
List<Type> implementz = new ArrayList<>();
while (implementsInterfacesContext != null) {
List<TypeName> typeNames = FpKit.map(implementsInterfacesContext.typeName(), this::createTypeName);

implementz.addAll(0, typeNames);
implementsInterfacesContext = implementsInterfacesContext.implementsInterfaces();
}
return implementz;
}
}
18 changes: 18 additions & 0 deletions src/main/java/graphql/schema/GraphQLImplementingType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package graphql.schema;

import graphql.PublicApi;

import java.util.List;

/**
* A GraphQLType which can implement interfaces
*/
@PublicApi
public interface GraphQLImplementingType extends GraphQLFieldsContainer {
/**
* @return This returns GraphQLInterface or GraphQLTypeReference instances, if the type
* references are not resolved yet. After they are resolved it contains only GraphQLInterface.
* Reference resolving happens when a full schema is built.
*/
List<GraphQLNamedOutputType> getInterfaces();
}
Loading