Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions src/main/java/graphql/schema/GraphQLAppliedDirectiveArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

Expand All @@ -34,6 +35,8 @@ public class GraphQLAppliedDirectiveArgument implements GraphQLNamedSchemaElemen
private final Argument definition;


public static final String CHILD_TYPE = "type";

private GraphQLAppliedDirectiveArgument(String name,
InputValueWithState value,
GraphQLInputType type,
Expand Down Expand Up @@ -104,19 +107,23 @@ public Argument getDefinition() {

@Override
public List<GraphQLSchemaElement> getChildren() {
return ImmutableKit.emptyList();
List<GraphQLSchemaElement> children = new ArrayList<>();
children.add(getType());
return children;
}


@Override
public SchemaElementChildrenContainer getChildrenWithTypeReferences() {
return SchemaElementChildrenContainer.newSchemaElementChildrenContainer()
.child(CHILD_TYPE, originalType)
.build();
}

@Override
public GraphQLAppliedDirectiveArgument withNewChildren(SchemaElementChildrenContainer newChildren) {
return this;
return transform(builder ->
builder.type(newChildren.getChildOrNull(CHILD_TYPE))
);
}

@Override
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/graphql/util/Breadcrumb.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import graphql.PublicApi;

import java.util.Objects;
import java.util.StringJoiner;

/**
* A specific {@link NodeLocation} inside a node. This means {@link #getNode()} returns a Node which has a child
Expand Down Expand Up @@ -47,9 +48,16 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int result = 1;
result = 31 * result + Objects.hashCode(node);
result = 31 * result + Objects.hashCode(node);
result = 31 * result + Objects.hashCode(location);
return result;
}

@Override
public String toString() {
return new StringJoiner(", ", "[", "]")
.add("" + location)
.add("" + node)
.toString();
}
}
2 changes: 1 addition & 1 deletion src/main/java/graphql/util/NodeLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int getIndex() {

@Override
public String toString() {
return "NodeLocation{" +
return "{" +
"name='" + name + '\'' +
", index=" + index +
'}';
Expand Down
46 changes: 46 additions & 0 deletions src/test/groovy/graphql/schema/SchemaTransformerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -870,4 +870,50 @@ type Query {
newSchema.getType("Foo") == null
(newSchema.getObjectType("Query").getFieldDefinition("field").getType() as GraphQLScalarType).getName() == "Bar"
}

def "rename scalars are changed in applied arguments"() {

def schema = TestUtil.schema("""
scalar Foo
directive @myDirective(fooArgOnDirective: Foo) on FIELD_DEFINITION
type Query {
foo(fooArgOnField: Foo) : Foo @myDirective
}
""")

def visitor = new GraphQLTypeVisitorStub() {

@Override
TraversalControl visitGraphQLScalarType(GraphQLScalarType node, TraverserContext<GraphQLSchemaElement> context) {
if (node.getName().equals("Foo")) {
GraphQLScalarType newNode = node.transform({sc -> sc.name("Bar")})
return changeNode(context, newNode)
}
return super.visitGraphQLScalarType(node, context)
}
}

when:
def newSchema = SchemaTransformer.transformSchema(schema, visitor)
then:

def fieldDef = newSchema.getObjectType("Query").getFieldDefinition("foo")
def appliedDirective = fieldDef.getAppliedDirective("myDirective")
def oldSkoolDirective = fieldDef.getDirective("myDirective")
def argument = fieldDef.getArgument("fooArgOnField")
def directiveDecl = newSchema.getDirective("myDirective")
def directiveArgument = directiveDecl.getArgument("fooArgOnDirective")

(fieldDef.getType() as GraphQLScalarType).getName() == "Bar"
(argument.getType() as GraphQLScalarType).getName() == "Bar"
(directiveArgument.getType() as GraphQLScalarType).getName() == "Bar"

(oldSkoolDirective.getArgument("fooArgOnDirective").getType() as GraphQLScalarType).getName() == "Bar"

newSchema.getType("Bar") instanceof GraphQLScalarType

// not working at this stage
(appliedDirective.getArgument("fooArgOnDirective").getType() as GraphQLScalarType).getName() == "Bar"
newSchema.getType("Foo") == null
}
}