-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update dgs implementation with latest schema changes (#177)
Related #166
- Loading branch information
1 parent
aeecfcb
commit 41267c6
Showing
10 changed files
with
186 additions
and
31 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
...java/com/netflix/graphql/dgs/compatibility/datafetchers/DeprecatedProductDataFetcher.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,26 @@ | ||
package com.netflix.graphql.dgs.compatibility.datafetchers; | ||
|
||
import com.netflix.graphql.dgs.DgsComponent; | ||
import com.netflix.graphql.dgs.DgsEntityFetcher; | ||
import com.netflix.graphql.dgs.DgsQuery; | ||
import com.netflix.graphql.dgs.InputArgument; | ||
import com.netflix.graphql.dgs.compatibility.model.DeprecatedProduct; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@DgsComponent | ||
public class DeprecatedProductDataFetcher { | ||
|
||
@DgsQuery(field = "deprecatedProduct") | ||
public DeprecatedProduct getDeprecatedProduct(@InputArgument String sku, @InputArgument("package") String pkg) { | ||
return DeprecatedProduct.resolveBySkuAndPackage(sku, pkg); | ||
} | ||
|
||
@DgsEntityFetcher(name = "DeprecatedProduct") | ||
public static DeprecatedProduct resolveReference(@NotNull Map<String, Object> reference) { | ||
if (reference.get("sku") instanceof String sku && reference.get("package") instanceof String pkg) { | ||
return DeprecatedProduct.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
25 changes: 25 additions & 0 deletions
25
...n/java/com/netflix/graphql/dgs/compatibility/datafetchers/ProductResearchDataFetcher.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,25 @@ | ||
package com.netflix.graphql.dgs.compatibility.datafetchers; | ||
|
||
import com.netflix.graphql.dgs.DgsComponent; | ||
import com.netflix.graphql.dgs.DgsEntityFetcher; | ||
import com.netflix.graphql.dgs.compatibility.model.ProductResearch; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
@DgsComponent | ||
public class ProductResearchDataFetcher { | ||
|
||
@DgsEntityFetcher(name = "ProductResearch") | ||
public static ProductResearch resolveReference(@NotNull Map<String, Object> reference) { | ||
if (reference.get("study") instanceof HashMap caseStudy) { | ||
if (caseStudy.get("caseNumber") instanceof String caseNumber) { | ||
return ProductResearch.RESEARCH_LIST.stream() | ||
.filter(research -> research.getStudy().getCaseNumber().equals(caseNumber)) | ||
.findAny() | ||
.orElse(null); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
implementations/dgs/src/main/java/com/netflix/graphql/dgs/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.netflix.graphql.dgs.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; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ions/dgs/src/main/java/com/netflix/graphql/dgs/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,40 @@ | ||
package com.netflix.graphql.dgs.compatibility.model; | ||
|
||
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, String reason) { | ||
this.sku = sku; | ||
this.pkg = pkg; | ||
this.reason = reason; | ||
this.createdBy = User.DEFAULT_USER; | ||
} | ||
|
||
public String getSku() { | ||
return sku; | ||
} | ||
|
||
public String getPackage() { | ||
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; | ||
} | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...ations/dgs/src/main/java/com/netflix/graphql/dgs/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,30 @@ | ||
package com.netflix.graphql.dgs.compatibility.model; | ||
|
||
import java.util.List; | ||
|
||
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; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
implementations/dgs/src/main/java/com/netflix/graphql/dgs/compatibility/model/User.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
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