Skip to content

Commit

Permalink
smallrye#521: consider @Name for resolving the federated type name
Browse files Browse the repository at this point in the history
  • Loading branch information
t1 authored and jmartisk committed Oct 3, 2022
1 parent 94595d3 commit 4a88445
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import javax.json.JsonReaderFactory;
import javax.json.bind.Jsonb;

import org.eclipse.microprofile.graphql.Name;

import com.apollographql.federation.graphqljava.Federation;

import graphql.introspection.Introspection.DirectiveLocation;
Expand Down Expand Up @@ -204,7 +206,9 @@ private TypeResolver fetchEntityType() {
if (src == null) {
return null;
}
GraphQLObjectType result = env.getSchema().getObjectType(src.getClass().getSimpleName()); // TODO respect @Name, etc.
Name annotation = src.getClass().getAnnotation(Name.class);
String typeName = (annotation == null) ? src.getClass().getSimpleName() : annotation.value();
GraphQLObjectType result = env.getSchema().getObjectType(typeName);
if (result == null) {
throw new RuntimeException("can't resolve federated entity type " + src.getClass().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

@GraphQLApi
public class ProductApi {
private static final List<Product> PRODUCTS = asList(
Product.product("1", "Armchair"),
Product.product("2", "Table"));
private static final List<ProductEntity> PRODUCTS = asList(
ProductEntity.product("1", "Armchair"),
ProductEntity.product("2", "Table"));

@Query
public Product product(@Id String id) {
public ProductEntity product(@Id String id) {
return PRODUCTS.stream()
.filter(product -> product.getId().equals(id))
.findFirst().orElseThrow(() -> new RuntimeException("product not find"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.smallrye.graphql.test.apps.federation;

import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Name;

import io.smallrye.graphql.api.federation.Key;

@Key(fields = "id")
public class Product {
static Product product(String id, String name) {
Product product = new Product();
@Name("Product")
public class ProductEntity {
static ProductEntity product(String id, String name) {
ProductEntity product = new ProductEntity();
product.setId(id);
product.setName(name);
return product;
Expand Down

0 comments on commit 4a88445

Please sign in to comment.