This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving the review example based on apollographql/federation-jvm#103
- Loading branch information
1 parent
780ebf8
commit 9a99fd4
Showing
5 changed files
with
69 additions
and
22 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
62 changes: 62 additions & 0 deletions
62
reviews/src/main/java/com/example/demo/federation/GraphQLJavaToolsConfiguration.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,62 @@ | ||
package com.example.demo.federation; | ||
|
||
import com.apollographql.federation.graphqljava.Federation; | ||
import com.apollographql.federation.graphqljava.SchemaTransformer; | ||
import com.example.demo.model.Show; | ||
import graphql.Scalars; | ||
import graphql.kickstart.tools.SchemaObjects; | ||
import graphql.kickstart.tools.SchemaParser; | ||
import graphql.kickstart.tools.SchemaParserDictionary; | ||
import graphql.kickstart.tools.SchemaParserOptions; | ||
import graphql.schema.GraphQLFieldDefinition; | ||
import graphql.schema.GraphQLObjectType; | ||
import graphql.schema.GraphQLSchema; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class GraphQLJavaToolsConfiguration { | ||
|
||
@Bean | ||
public SchemaParserDictionary schemaParserDictionary() { | ||
return new SchemaParserDictionary().add("Show", Show.class); | ||
} | ||
|
||
@Bean | ||
public BeanPostProcessor schemaParserOptionsBuilderPostProcessor() { | ||
return new BeanPostProcessor() { | ||
@Override | ||
public Object postProcessAfterInitialization(@NotNull Object bean, @NotNull String beanName) throws BeansException { | ||
return bean instanceof SchemaParserOptions.Builder | ||
? ((SchemaParserOptions.Builder) bean).includeUnusedTypes(true) : bean; | ||
} | ||
}; | ||
} | ||
|
||
|
||
@Bean | ||
public SchemaTransformer schemaTransformer(SchemaParser schemaParser) { | ||
final SchemaObjects schemaObjects = schemaParser.parseSchemaObjects(); | ||
final boolean queryTypeIsEmpty = schemaObjects.getQuery().getFieldDefinitions().isEmpty(); | ||
final GraphQLObjectType newQuery = queryTypeIsEmpty | ||
? schemaObjects.getQuery().transform(graphQLObjectTypeBuilder -> | ||
graphQLObjectTypeBuilder.field(GraphQLFieldDefinition.newFieldDefinition() | ||
.name("_dummy") | ||
.type(Scalars.GraphQLString) | ||
.build() | ||
) | ||
) | ||
: schemaObjects.getQuery(); | ||
final GraphQLSchema graphQLSchema = GraphQLSchema.newSchema() | ||
.query(newQuery) | ||
.mutation(schemaObjects.getMutation()) | ||
.subscription(schemaObjects.getSubscription()) | ||
.additionalTypes(schemaObjects.getDictionary()) | ||
.codeRegistry(schemaObjects.getCodeRegistryBuilder().build()) | ||
.build(); | ||
return Federation.transform(graphQLSchema, queryTypeIsEmpty); | ||
} | ||
} |
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