-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from apollographql/sachin/upgrade-graphql-spr…
…ing-boot-to-11.0.0 spring-example: Upgrade graphql-spring-boot-starter to 11.0.0
- Loading branch information
Showing
21 changed files
with
361 additions
and
108 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
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
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
8 changes: 0 additions & 8 deletions
8
spring-example/src/main/java/com/apollographql/federation/springexample/App.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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
package com.apollographql.federation.springexample; | ||
|
||
import com.apollographql.federation.graphqljava.tracing.FederatedTracingInstrumentation; | ||
import graphql.execution.instrumentation.Instrumentation; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class App { | ||
public static void main(String[] args) { | ||
SpringApplication.run(App.class, args); | ||
} | ||
|
||
@Bean | ||
public Instrumentation addFederatedTracing() { | ||
return new FederatedTracingInstrumentation(new FederatedTracingInstrumentation.Options(true)); | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
...ple/src/main/java/com/apollographql/federation/springexample/InventorySchemaProvider.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...rc/main/java/com/apollographql/federation/springexample/graphqljava/AppConfiguration.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,47 @@ | ||
package com.apollographql.federation.springexample.graphqljava; | ||
|
||
import com.apollographql.federation.graphqljava.Federation; | ||
import com.apollographql.federation.graphqljava._Entity; | ||
import com.apollographql.federation.graphqljava.tracing.FederatedTracingInstrumentation; | ||
import graphql.schema.GraphQLSchema; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.io.Resource; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Configuration | ||
@Profile("graphql-java") | ||
public class AppConfiguration { | ||
@Bean | ||
public GraphQLSchema graphQLSchema(@Value("classpath:schemas/graphql-java/inventory.graphql") Resource sdl) throws IOException { | ||
return Federation.transform(sdl.getFile()) | ||
.fetchEntities(env -> env.<List<Map<String, Object>>>getArgument(_Entity.argumentName) | ||
.stream() | ||
.map(reference -> { | ||
if ("Product".equals(reference.get("__typename"))) { | ||
return Product.resolveReference(reference); | ||
} | ||
return null; | ||
}) | ||
.collect(Collectors.toList())) | ||
.resolveEntityType(env -> { | ||
final Object src = env.getObject(); | ||
if (src instanceof Product) { | ||
return env.getSchema().getObjectType("Product"); | ||
} | ||
return null; | ||
}) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public FederatedTracingInstrumentation federatedTracingInstrumentation() { | ||
return new FederatedTracingInstrumentation(new FederatedTracingInstrumentation.Options(true)); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...example/src/main/java/com/apollographql/federation/springexample/graphqljava/Product.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,49 @@ | ||
package com.apollographql.federation.springexample.graphqljava; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.math.BigInteger; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Map; | ||
|
||
public class Product { | ||
private final String upc; | ||
private final int quantity; | ||
|
||
public Product(String upc, int quantity) { | ||
this.upc = upc; | ||
this.quantity = quantity; | ||
} | ||
|
||
public String getUpc() { | ||
return upc; | ||
} | ||
|
||
public int getQuantity() { | ||
return quantity; | ||
} | ||
|
||
public boolean isInStock() { | ||
return this.quantity > 0; | ||
} | ||
|
||
public static Product resolveReference(@NotNull Map<String, Object> reference) { | ||
if (!(reference.get("upc") instanceof String)) { | ||
return null; | ||
} | ||
final String upc = (String) reference.get("upc"); | ||
try { | ||
// Why not? | ||
int quantity = Math.floorMod( | ||
new BigInteger(1, | ||
MessageDigest.getInstance("SHA1").digest(upc.getBytes()) | ||
).intValue(), | ||
10_000); | ||
|
||
return new Product(upc, quantity); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...in/java/com/apollographql/federation/springexample/graphqljavatools/AppConfiguration.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,44 @@ | ||
package com.apollographql.federation.springexample.graphqljavatools; | ||
|
||
import com.apollographql.federation.graphqljava.SchemaTransformer; | ||
import com.apollographql.federation.graphqljava._Entity; | ||
import com.apollographql.federation.graphqljava.tracing.FederatedTracingInstrumentation; | ||
import graphql.schema.GraphQLSchema; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
@Configuration | ||
@Profile("graphql-java-tools") | ||
public class AppConfiguration { | ||
@Bean | ||
public GraphQLSchema graphQLSchema(SchemaTransformer schemaTransformer) { | ||
return schemaTransformer | ||
.fetchEntities(env -> env.<List<Map<String, Object>>>getArgument(_Entity.argumentName) | ||
.stream() | ||
.map(reference -> { | ||
if ("Product".equals(reference.get("__typename"))) { | ||
return ProductReferenceResolver.resolveReference(reference); | ||
} | ||
return null; | ||
}) | ||
.collect(Collectors.toList())) | ||
.resolveEntityType(env -> { | ||
final Object src = env.getObject(); | ||
if (src instanceof Product) { | ||
return env.getSchema().getObjectType("Product"); | ||
} | ||
return null; | ||
}) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public FederatedTracingInstrumentation federatedTracingInstrumentation() { | ||
return new FederatedTracingInstrumentation(new FederatedTracingInstrumentation.Options(true)); | ||
} | ||
} |
Oops, something went wrong.