Iterate over implementations in isPossibleType by xuorig · Pull Request #4033 · graphql-java/graphql-java · GitHub
Skip to content
Closed
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
22 changes: 19 additions & 3 deletions src/main/java/graphql/schema/idl/TypeDefinitionRegistry.java
19 changes: 19 additions & 0 deletions src/main/java/graphql/schema/idl/TypeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ public static TypeInfo typeInfo(Type type) {
return new TypeInfo(type);
}

/**
* Gets the type name of a [Type], unwrapping any lists or non-null decorations
*
* @param type the Type
*
* @return the inner TypeName for this type
*/
public static TypeName getTypeName(Type type) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

What TypeInfo gave us, but without allocation of a TypeInfo object and without the tracking of decorations.

while (!(type instanceof TypeName)) {
if (type instanceof NonNullType) {
type = ((NonNullType) type).getType();
}
if (type instanceof ListType) {
type = ((ListType) type).getType();
}
}
return (TypeName) type;
}

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.

This needs a unit test and some JavaDoc

private final Type rawType;
private final TypeName typeName;
private final Deque<Class<?>> decoration = new ArrayDeque<>();
Expand Down
17 changes: 17 additions & 0 deletions src/test/groovy/graphql/schema/idl/TypeInfoTest.groovy