Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
16 changes: 14 additions & 2 deletions 16 src/main/java/graphql/schema/GraphQLArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.PublicApi;
import graphql.language.InputValueDefinition;
import graphql.util.FpKit;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -71,8 +73,8 @@ private GraphQLArgument(String name, String description, GraphQLInputType type,
}


void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
type = (GraphQLInputType) new SchemaUtil().resolveTypeReference(type, typeMap);
void replaceType(GraphQLInputType type) {
this.type = type;
}

@Override
Expand Down Expand Up @@ -140,6 +142,16 @@ public static Builder newArgument(GraphQLArgument existing) {
return new Builder(existing);
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLArgument(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return Collections.singletonList(type);
}

public static class Builder {

private String name;
Expand Down
12 changes: 12 additions & 0 deletions 12 src/main/java/graphql/schema/GraphQLEnumType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import graphql.PublicApi;
import graphql.language.EnumTypeDefinition;
import graphql.language.EnumValue;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -175,6 +177,16 @@ public GraphQLEnumType transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLEnumType(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return new ArrayList<>(valueDefinitionMap.values());
}

public static Builder newEnum() {
return new Builder();
}
Expand Down
8 changes: 8 additions & 0 deletions 8 src/main/java/graphql/schema/GraphQLEnumValueDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.DirectivesUtil;
import graphql.Internal;
import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -105,6 +107,12 @@ public GraphQLEnumValueDefinition transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLEnumValueDefinition(this, context);
}


public static Builder newEnumValueDefinition() {
return new Builder();
}
Expand Down
20 changes: 17 additions & 3 deletions 20 src/main/java/graphql/schema/GraphQLFieldDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.FieldDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -64,9 +66,8 @@ public GraphQLFieldDefinition(String name, String description, GraphQLOutputType
this.definition = definition;
}


void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
this.type = (GraphQLOutputType) new SchemaUtil().resolveTypeReference(this.type, typeMap);
void replaceType(GraphQLOutputType type) {
this.type = type;
}

@Override
Expand Down Expand Up @@ -144,6 +145,19 @@ public GraphQLFieldDefinition transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLFieldDefinition(this, context);
}

@Override
public List<GraphQLType> getChildren() {
List<GraphQLType> children = new ArrayList<>();
children.add(type);
children.addAll(arguments);
return children;
}

public static Builder newFieldDefinition(GraphQLFieldDefinition existing) {
return new Builder(existing);
}
Expand Down
17 changes: 15 additions & 2 deletions 17 src/main/java/graphql/schema/GraphQLInputObjectField.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.InputValueDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -59,8 +62,8 @@ public GraphQLInputObjectField(String name, String description, GraphQLInputType
this.definition = definition;
}

void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
type = (GraphQLInputType) new SchemaUtil().resolveTypeReference(type, typeMap);
void replaceType(GraphQLInputType type) {
this.type = type;
}

@Override
Expand Down Expand Up @@ -103,6 +106,16 @@ public GraphQLInputObjectField transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLInputObjectField(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return Collections.singletonList(type);
}

public static Builder newInputObjectField(GraphQLInputObjectField existing) {
return new Builder(existing);
}
Expand Down
12 changes: 12 additions & 0 deletions 12 src/main/java/graphql/schema/GraphQLInputObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.InputObjectTypeDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -110,6 +112,16 @@ public GraphQLInputObjectType transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLInputObjectType(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return new ArrayList<>(fieldMap.values());
}

public static Builder newInputObject(GraphQLInputObjectType existing) {
return new Builder(existing);
}
Expand Down
12 changes: 12 additions & 0 deletions 12 src/main/java/graphql/schema/GraphQLInterfaceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.InterfaceTypeDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -125,6 +127,16 @@ public GraphQLInterfaceType transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLInterfaceType(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return new ArrayList<>(fieldDefinitionsByName.values());
}

public static Builder newInterface() {
return new Builder();
}
Expand Down
18 changes: 16 additions & 2 deletions 18 src/main/java/graphql/schema/GraphQLList.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static graphql.Assert.assertNotNull;
Expand Down Expand Up @@ -41,8 +45,8 @@ public GraphQLType getWrappedType() {
return wrappedType;
}

void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
wrappedType = new SchemaUtil().resolveTypeReference(wrappedType, typeMap);
void replaceType(GraphQLType type) {
wrappedType = type;
}

@Override
Expand All @@ -65,4 +69,14 @@ public int hashCode() {
public String getName() {
return null;
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLList(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return Collections.singletonList(wrappedType);
}
}
19 changes: 17 additions & 2 deletions 19 src/main/java/graphql/schema/GraphQLNonNull.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static graphql.Assert.assertNotNull;
Expand Down Expand Up @@ -41,8 +45,9 @@ public GraphQLType getWrappedType() {
return wrappedType;
}

void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
wrappedType = new SchemaUtil().resolveTypeReference(wrappedType, typeMap);

void replaceType(GraphQLType type) {
wrappedType = type;
}

@Override
Expand Down Expand Up @@ -72,4 +77,14 @@ public String toString() {
public String getName() {
return null;
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLNonNull(this, context);
}

@Override
public List<GraphQLType> getChildren() {
return Collections.singletonList(wrappedType);
}
}
20 changes: 16 additions & 4 deletions 20 src/main/java/graphql/schema/GraphQLObjectType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.ObjectTypeDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -60,10 +62,8 @@ public GraphQLObjectType(String name, String description, List<GraphQLFieldDefin
buildDefinitionMap(fieldDefinitions);
}

void replaceTypeReferences(Map<String, GraphQLType> typeMap) {
this.interfaces = this.interfaces.stream()
.map(type -> (GraphQLOutputType) new SchemaUtil().resolveTypeReference(type, typeMap))
.collect(Collectors.toList());
void replaceInterfaces(List<GraphQLOutputType> interfaces) {
this.interfaces = interfaces;
}

private void buildDefinitionMap(List<GraphQLFieldDefinition> fieldDefinitions) {
Expand Down Expand Up @@ -138,6 +138,18 @@ public GraphQLObjectType transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLObjectType(this, context);
}

@Override
public List<GraphQLType> getChildren() {
List<GraphQLType> children = new ArrayList<>(fieldDefinitionsByName.values());
children.addAll(interfaces);
return children;
}

public static Builder newObject() {
return new Builder();
}
Expand Down
7 changes: 7 additions & 0 deletions 7 src/main/java/graphql/schema/GraphQLScalarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import graphql.Internal;
import graphql.PublicApi;
import graphql.language.ScalarTypeDefinition;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -105,6 +107,11 @@ public GraphQLScalarType transform(Consumer<Builder> builderConsumer) {
return builder.build();
}

@Override
public TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor) {
return visitor.visitGraphQLScalarType(this, context);
}

public static Builder newScalar() {
return new Builder();
}
Expand Down
25 changes: 25 additions & 0 deletions 25 src/main/java/graphql/schema/GraphQLType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


import graphql.PublicApi;
import graphql.util.TraversalControl;
import graphql.util.TraverserContext;

import java.util.Collections;
import java.util.List;

/**
* All types in graphql have a name
Expand All @@ -12,4 +17,24 @@ public interface GraphQLType {
* @return the name of the type which MUST fit within the regular expression {@code [_A-Za-z][_0-9A-Za-z]*}
*/
String getName();

/**
* @return returns all types directly associated with this node
*/
default List<GraphQLType> getChildren() { return Collections.emptyList(); }

/**
* Double-dispatch entry point.
*
* It allows to travers a given non-trivial graphQL type and move from root to nested or enclosed types.
*
* This implements similar pattern as {@link graphql.language.Node}, see accept(...) for more details about the pattern.
*
* @param context TraverserContext bound to this graphQL type object
* @param visitor Visitor instance that performs actual processing on the types(s)
*
* @return Result of Visitor's operation.
* Note! Visitor's operation might return special results to control traversal process.
*/
TraversalControl accept(TraverserContext<GraphQLType> context, GraphQLTypeVisitor visitor);
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.