|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -112,16 +112,21 @@ public boolean providesDataFetcher(FieldWiringEnvironment environment) {
|
112 | 112 |
|
113 | 113 | @Nullable
|
114 | 114 | private String getOutputTypeName(FieldWiringEnvironment environment) {
|
115 |
| - GraphQLType outputType = (environment.getFieldType() instanceof GraphQLList ? |
116 |
| - ((GraphQLList) environment.getFieldType()).getWrappedType() : |
117 |
| - environment.getFieldType()); |
| 115 | + GraphQLType outputType = removeNonNullWrapper(environment.getFieldType()); |
118 | 116 |
|
119 |
| - if (outputType instanceof GraphQLNonNull) { |
120 |
| - outputType = ((GraphQLNonNull) outputType).getWrappedType(); |
| 117 | + if (outputType instanceof GraphQLList) { |
| 118 | + outputType = removeNonNullWrapper(((GraphQLList) outputType).getWrappedType()); |
121 | 119 | }
|
122 | 120 |
|
123 |
| - return (outputType instanceof GraphQLNamedOutputType ? |
124 |
| - ((GraphQLNamedOutputType) outputType).getName() : null); |
| 121 | + if (outputType instanceof GraphQLNamedOutputType namedType) { |
| 122 | + return namedType.getName(); |
| 123 | + } |
| 124 | + |
| 125 | + return null; |
| 126 | + } |
| 127 | + |
| 128 | + private GraphQLType removeNonNullWrapper(GraphQLType outputType) { |
| 129 | + return (outputType instanceof GraphQLNonNull wrapper ? wrapper.getWrappedType() : outputType); |
125 | 130 | }
|
126 | 131 |
|
127 | 132 | private boolean hasDataFetcherFor(FieldDefinition fieldDefinition) {
|
@@ -152,8 +157,8 @@ public DataFetcher<?> getDataFetcher(FieldWiringEnvironment environment) {
|
152 | 157 | Function<Boolean, DataFetcher<?>> factory = dataFetcherFactories.get(outputTypeName);
|
153 | 158 | Assert.notNull(factory, "Expected DataFetcher factory for typeName '" + outputTypeName + "'");
|
154 | 159 |
|
155 |
| - boolean single = !(environment.getFieldType() instanceof GraphQLList); |
156 |
| - return factory.apply(single); |
| 160 | + GraphQLType type = removeNonNullWrapper(environment.getFieldType()); |
| 161 | + return factory.apply(!(type instanceof GraphQLList)); |
157 | 162 | }
|
158 | 163 |
|
159 | 164 | }
|
|
0 commit comments