Skip to content

Commit

Permalink
Fix handling of concrete type datafetchers for interface fields. (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasankavitha authored Nov 3, 2023
1 parent e726e3b commit c022e61
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2021 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.graphql.dgs.example.shared.datafetcher;

import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;

@DgsComponent
public class ActionMovieDataFetcher {
@SuppressWarnings("SameReturnValue")
@DgsData(parentType = "ActionMovie", field = "director")
public String director() {

return "Action movie director";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.netflix.graphql.dgs.example.shared.datafetcher;

import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsData;
import com.netflix.graphql.dgs.example.shared.types.ActionMovie;
import com.netflix.graphql.dgs.example.shared.types.Movie;
import com.netflix.graphql.dgs.example.shared.types.ScaryMovie;
import graphql.schema.DataFetchingEnvironment;

import java.util.ArrayList;
import java.util.List;

@DgsComponent
public class ScaryMovieDataFetcher {
@SuppressWarnings("SameReturnValue")
@DgsData(parentType = "ScaryMovie", field = "director")
public String director() {

return "Scary movie director";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,20 @@ class DgsSchemaProvider(
}
val implementationsOf = typeDefinitionRegistry.getImplementationsOf(type)
implementationsOf.forEach { implType ->
val dataFetcher =
createBasicDataFetcher(method, dgsComponent, parentType == "Subscription")
codeRegistryBuilder.dataFetcher(
FieldCoordinates.coordinates(implType.name, field),
dataFetcher
)
dataFetcherTracingInstrumentationEnabled["${implType.name}.$field"] = enableTracingInstrumentation
dataFetcherMetricsInstrumentationEnabled["${implType.name}.$field"] = enableMetricsInstrumentation
// if we have a datafetcher explicitly defined for a parentType/field, use that and do not
// register the base implementation for interfaces
if (!codeRegistryBuilder.hasDataFetcher(FieldCoordinates.coordinates(implType.name, field))) {
val dataFetcher =
createBasicDataFetcher(method, dgsComponent, parentType == "Subscription")
codeRegistryBuilder.dataFetcher(
FieldCoordinates.coordinates(implType.name, field),
dataFetcher
)
dataFetcherTracingInstrumentationEnabled["${implType.name}.$field"] =
enableTracingInstrumentation
dataFetcherMetricsInstrumentationEnabled["${implType.name}.$field"] =
enableMetricsInstrumentation
}
}
}
is UnionTypeDefinition -> {
Expand Down

0 comments on commit c022e61

Please sign in to comment.