Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Upgrade to graphql-tools 5.4 for type definition factory and directive #161

Merged
merged 2 commits into from
Nov 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.module.kotlin.KotlinModule;
import graphql.schema.GraphQLScalarType;
import graphql.schema.GraphQLSchema;
import graphql.schema.idl.SchemaDirectiveWiring;
import graphql.servlet.GraphQLSchemaProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
Expand Down Expand Up @@ -41,6 +42,12 @@ public class GraphQLJavaToolsAutoConfiguration {
@Autowired(required = false)
private SchemaParserOptions options;

@Autowired(required = false)
private List<SchemaDirective> directives;

@Autowired(required = false)
private List<TypeDefinitionFactory> typeDefinitionFactories;

@Autowired
private GraphQLToolsProperties props;

Expand All @@ -67,15 +74,28 @@ public SchemaParser schemaParser(
builder.scalars(scalars);
}

// fixme: should we even support options directly like this? the combination with the builder makes it complex
if (options != null) {
builder.options(options);
} else if (perFieldObjectMapperProvider != null) {
final SchemaParserOptions.Builder optionsBuilder =
newOptions().objectMapperProvider(perFieldObjectMapperProvider);
} else {
SchemaParserOptions.Builder optionsBuilder = SchemaParserOptions.newOptions();

if (perFieldObjectMapperProvider != null) {
optionsBuilder.objectMapperProvider(perFieldObjectMapperProvider);
}
optionsBuilder.introspectionEnabled(props.isIntrospectionEnabled());

if (typeDefinitionFactories != null) {
typeDefinitionFactories.forEach(optionsBuilder::typeDefinitionFactory);
}

builder.options(optionsBuilder.build());
}

if (directives != null) {
directives.forEach(it -> builder.directive(it.getName(), it.getDirective()));
}

return builder
.resolvers(resolvers)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.oembedler.moon.graphql.boot;

import graphql.schema.idl.SchemaDirectiveWiring;

public interface SchemaDirective {

String getName();

SchemaDirectiveWiring getDirective();

static SchemaDirective create(String name, SchemaDirectiveWiring directive) {
return new SchemaDirectiveImpl(name, directive);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.oembedler.moon.graphql.boot;

import graphql.schema.idl.SchemaDirectiveWiring;

class SchemaDirectiveImpl implements SchemaDirective {

private final String name;
private final SchemaDirectiveWiring directive;

SchemaDirectiveImpl(String name, SchemaDirectiveWiring directive) {
this.name = name;
this.directive = directive;
}

@Override
public String getName() {
return name;
}

@Override
public SchemaDirectiveWiring getDirective() {
return directive;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,6 @@ public void schemaWithInterfaceLoads() {

Assert.assertNotNull(this.getContext().getBean(GraphQLSchema.class));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.oembedler.moon.graphql.boot.test.graphqlJavaTools;

import com.coxautodev.graphql.tools.GraphQLQueryResolver;
import com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration;
import com.oembedler.moon.graphql.boot.SchemaDirective;
import com.oembedler.moon.graphql.boot.test.AbstractAutoConfigurationTest;
import graphql.schema.GraphQLObjectType;
import graphql.schema.idl.SchemaDirectiveWiring;
import graphql.schema.idl.SchemaDirectiveWiringEnvironment;
import graphql.schema.idl.SchemaParser;
import org.junit.Test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import static org.junit.Assert.assertNotNull;

public class GraphQLToolsDirectiveTest extends AbstractAutoConfigurationTest {

public GraphQLToolsDirectiveTest() {
super(GraphQLJavaToolsAutoConfiguration.class);
}

@Test
public void directiveIsLoaded() {
System.setProperty("graphql.tools.schemaLocationPattern", "graphql/schema-directive-test.graphql");
load(BaseConfiguration.class);
}

@Configuration
static class BaseConfiguration {

@Component
public class Query implements GraphQLQueryResolver {
String schemaLocationTest(String id) {
return id;
}
}

@Bean
public SchemaDirective uppercaseDirective() {
return SchemaDirective.create("uppercase", new SchemaDirectiveWiring() {
@Override
public GraphQLObjectType onObject(SchemaDirectiveWiringEnvironment<GraphQLObjectType> environment) {
return null;
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type Query {
schemaLocationTest(id: ID!): String
}