-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update federation-jvm implementation with latest schema changes (#173)
Related: #166
- Loading branch information
1 parent
80b958b
commit 820f3a3
Showing
9 changed files
with
234 additions
and
37 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...src/main/java/com/apollographql/federation/compatibility/DeprecatedProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.apollographql.federation.compatibility; | ||
|
||
import com.apollographql.federation.compatibility.model.DeprecatedProduct; | ||
import org.springframework.graphql.data.method.annotation.Argument; | ||
import org.springframework.graphql.data.method.annotation.QueryMapping; | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
public class DeprecatedProductController { | ||
|
||
@QueryMapping | ||
public DeprecatedProduct deprecatedProduct(@Argument String sku, @Argument("package") String pkg) { | ||
return DeprecatedProduct.resolveBySkuAndPackage(sku, pkg); | ||
} | ||
|
||
@SchemaMapping(typeName="DeprecatedProduct", field="package") | ||
public String getPackage(DeprecatedProduct product) { | ||
return product.getPkg(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...eration-jvm/src/main/java/com/apollographql/federation/compatibility/model/CaseStudy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.apollographql.federation.compatibility.model; | ||
|
||
public class CaseStudy { | ||
private final String caseNumber; | ||
private final String description; | ||
|
||
public CaseStudy(String caseNumber, String description) { | ||
this.caseNumber = caseNumber; | ||
this.description = description; | ||
} | ||
|
||
public String getCaseNumber() { | ||
return caseNumber; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...jvm/src/main/java/com/apollographql/federation/compatibility/model/DeprecatedProduct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.apollographql.federation.compatibility.model; | ||
|
||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DeprecatedProduct { | ||
|
||
public static DeprecatedProduct DEPRECATED_PRODUCT = new DeprecatedProduct("apollo-federation-v1", "@apollo/federation-v1", "Migrate to Federation V2"); | ||
|
||
private final String sku; | ||
private final String pkg; | ||
private final String reason; | ||
private final User createdBy; | ||
|
||
public DeprecatedProduct(String sku, String pkg) { | ||
this.sku = sku; | ||
this.pkg = pkg; | ||
this.reason = null; | ||
this.createdBy = User.DEFAULT_USER; | ||
} | ||
|
||
public DeprecatedProduct(String sku, String pkg, String reason) { | ||
this.sku = sku; | ||
this.pkg = pkg; | ||
this.reason = reason; | ||
this.createdBy = User.DEFAULT_USER; | ||
} | ||
|
||
public DeprecatedProduct(String sku, String pkg, String reason, User createdBy) { | ||
this.sku = sku; | ||
this.pkg = pkg; | ||
this.reason = reason; | ||
this.createdBy = createdBy; | ||
} | ||
|
||
public String getSku() { | ||
return sku; | ||
} | ||
|
||
public String getPkg() { | ||
return pkg; | ||
} | ||
|
||
public String getReason() { | ||
return reason; | ||
} | ||
|
||
public User getCreatedBy() { | ||
return createdBy; | ||
} | ||
|
||
public static DeprecatedProduct resolveBySkuAndPackage(String sku, String pkg) { | ||
if (DEPRECATED_PRODUCT.sku.equals(sku) && DEPRECATED_PRODUCT.pkg.equals(pkg)) { | ||
return DEPRECATED_PRODUCT; | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public static DeprecatedProduct resolveReference(@NotNull Map<String, Object> reference) { | ||
if (reference.get("sku") instanceof String sku && reference.get("package") instanceof String pkg) { | ||
return resolveBySkuAndPackage(sku, pkg); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...n-jvm/src/main/java/com/apollographql/federation/compatibility/model/ProductResearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.apollographql.federation.compatibility.model; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ProductResearch { | ||
public static final ProductResearch FEDERATION_STUDY = new ProductResearch(new CaseStudy("1234", "Federation Study")); | ||
public static final ProductResearch STUDIO_STUDY = new ProductResearch(new CaseStudy("1235", "Studio Study")); | ||
public static final List<ProductResearch> RESEARCH_LIST = List.of(FEDERATION_STUDY, STUDIO_STUDY); | ||
|
||
private final CaseStudy study; | ||
private final String outcome; | ||
|
||
public ProductResearch(CaseStudy study) { | ||
this.study = study; | ||
this.outcome = null; | ||
} | ||
|
||
public ProductResearch(CaseStudy study, String outcome) { | ||
this.study = study; | ||
this.outcome = outcome; | ||
} | ||
|
||
public CaseStudy getStudy() { | ||
return study; | ||
} | ||
|
||
public String getOutcome() { | ||
return outcome; | ||
} | ||
|
||
public static ProductResearch resolveReference(@NotNull Map<String, Object> reference) { | ||
if (reference.get("study") instanceof HashMap caseStudy) { | ||
if (caseStudy.get("caseNumber") instanceof String caseNumber) { | ||
return RESEARCH_LIST.stream() | ||
.filter(research -> research.study.getCaseNumber().equals(caseNumber)) | ||
.findAny() | ||
.orElse(null); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.