Skip to content

Commit

Permalink
first tests for federation
Browse files Browse the repository at this point in the history
  • Loading branch information
t1 committed May 27, 2022
1 parent e57eb42 commit 0d90a1f
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,7 @@ public interface SmallRyeGraphQLServerLogging {
@Message(id = 15000, value = "Using %s service for context propagation")
void usingContextPropagationService(String name);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 16000, value = "Enable GraphQL Federation")
void enableFederation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ private void generateGraphQLSchema() {
JsonInputRegistry.override(overrides);

if (Config.get().isFederationEnabled()) {
log.enableFederation();
GraphQLSchema rawSchema = schemaBuilder.build();
this.graphQLSchema = Federation.transform(rawSchema)
.fetchEntities(new FederationDataFetcher(rawSchema.getQueryType(), rawSchema.getCodeRegistry()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ smallrye.graphql.printDataFetcherException=true
smallrye.graphql.tracing.enabled=true
smallrye.graphql.allowGet=true
smallrye.graphql.logPayload=true

mp.graphql.showErrorMessage=java.security.AccessControlException,io.smallrye.graphql.test.apps.exceptionlist.*
mp.graphql.hideErrorMessage=java.io.IOException,io.smallrye.graphql.test.apps.exceptionlist.*
smallrye.graphql.errorExtensionFields=exception,classification,code,description,validationErrorType,queryPath
smallrye.graphql.errorExtensionFields=exception,classification,code,description,validationErrorType,queryPath
smallrye.graphql.federation.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.smallrye.graphql.test.apps.federation.price.api;

import static java.util.Arrays.asList;

import java.util.List;

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Query;

@GraphQLApi
public class Prices {
private static final List<ProductWithPrice> PRICES = asList(
ProductWithPrice.product("1", 100),
ProductWithPrice.product("2", 400));

@Query
public ProductWithPrice product(@Id String id) {
return PRICES.stream()
.filter(productWithPrice -> productWithPrice.getId().equals(id))
.findFirst().orElseThrow(() -> new RuntimeException("product not find"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.smallrye.graphql.test.apps.federation.price.api;

import org.eclipse.microprofile.graphql.Id;

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

/**
* In a real federated service, this would also be a {@code Price}, but we can't have the same type twice within one service.
*/
@Key(fields = "id")
@Extends
public class ProductWithPrice {
public static ProductWithPrice product(String id, int price) {
ProductWithPrice product = new ProductWithPrice();
product.setId(id);
product.setPrice(price);
return product;
}

@Id
private String id;
private int price;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.smallrye.graphql.test.apps.federation.product.api;

import org.eclipse.microprofile.graphql.Id;

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

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

@Id
private String id;
private String name;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.smallrye.graphql.test.apps.federation.product.api;

import static java.util.Arrays.asList;

import java.util.List;

import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Id;
import org.eclipse.microprofile.graphql.Query;

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

@Query
public Product product(@Id String id) {
return PRODUCTS.stream()
.filter(product -> product.getId().equals(id))
.findFirst().orElseThrow(() -> new RuntimeException("product not find"));
}
}
8 changes: 8 additions & 0 deletions server/tck/src/test/resources/tests/federation/input.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
deepList{
names
}
deepListFoo{
bar
}
}
24 changes: 24 additions & 0 deletions server/tck/src/test/resources/tests/federation/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"data": {
"deepList": [
[
[
{
"names": [
"Phillip"
]
}
]
]
],
"deepListFoo": [
[
[
{
"bar": "bar"
}
]
]
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore=false
priority=100

0 comments on commit 0d90a1f

Please sign in to comment.