package gql.ratpack;

import javax.inject.Inject;
import javax.inject.Provider;

import graphql.GraphQL;
import graphql.execution.instrumentation.Instrumentation;
import graphql.schema.GraphQLSchema;

public class GraphQLProvider implements Provider<GraphQL> {

  private final GraphQLSchema graphQLSchema;
  private final Instrumentation instrumentation;

  @Inject
  public GraphQLProvider(GraphQLSchema schema, Instrumentation instrumentation) {
    this.graphQLSchema = schema;
    this.instrumentation = instrumentation;
  }

  @Override
  public GraphQL get() {
    return GraphQL
      .newGraphQL(graphQLSchema)
      .instrumentation(instrumentation)
      .build();
  }
}

@@ -35,22 +35,24 @@
 .inject.
-Inject
+Provider
 ;%0Aimport
@@ -56,35 +56,65 @@
 ort java
-x.inject.Provider;%0A
+.util.Optional;%0A%0Aimport com.google.inject.Inject;
 %0Aimport 
@@ -226,16 +226,136 @@
 chema;%0A%0A
+/**%0A * Creates an instance of %7B@link GraphQL%7D that can be reused among all%0A * incoming requests.%0A *%0A * @since 0.3.2%0A */%0A
 public c
@@ -417,22 +417,16 @@
 private 
-final 
 GraphQLS
@@ -460,14 +460,8 @@
 ate 
-final 
 Inst
@@ -496,62 +496,247 @@
 %0A%0A  
-@Inject%0A  public GraphQLProvider(GraphQLSchema schema,
+/**%0A   * Sets the %7B@link GraphQLSchema%7D instance. This is a hard%0A   * dependency%0A   *%0A   * @since 0.3.2%0A   */%0A  @Inject%0A  public void setGraphQLSchema(GraphQLSchema schema) %7B%0A    this.graphQLSchema = schema;%0A  %7D%0A%0A  /**%0A   * Sets the %7B@link
  Ins
@@ -751,60 +751,179 @@
 tion
+%7D
  inst
-rumentation) %7B%0A    this.graphQLSchema = schema;
+ance used. This is a soft%0A   * dependency%0A   *%0A   * @since 0.3.2%0A   */%0A  @Inject(optional = true)%0A  public void setInstrumentation(Instrumentation instrumentation) %7B
 %0A   
@@ -1013,22 +1013,21 @@
     
-return
+final
  GraphQL
 %0A   
@@ -1026,96 +1026,203 @@
 phQL
-%0A      .newGraphQL(graphQLSchema)%0A      .instrumentation(instrumentation)%0A      
+.Builder builder = GraphQL.newGraphQL(graphQLSchema);%0A%0A    return Optional%0A      .ofNullable(instrumentation)%0A      .map(ins -%3E builder.instrumentation(ins).build())%0A      .orElse(builder
 .build()
 ;%0A  
@@ -1217,16 +1217,17 @@
 .build()
+)
 ;%0A  %7D%0A%7D%0A

Fix instrumentation dependency from mandatory -> optional