graphql.schema.idl.EchoingWiringFactory Maven / Gradle / Ivy
package graphql.schema.idl;
import graphql.Internal;
import graphql.Scalars;
import graphql.schema.Coercing;
import graphql.schema.DataFetcher;
import graphql.schema.GraphQLObjectType;
import graphql.schema.GraphQLOutputType;
import graphql.schema.GraphQLScalarType;
import graphql.schema.PropertyDataFetcher;
import graphql.schema.TypeResolver;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Consumer;
/**
* A wiring factory that will echo back the objects defined. That is if you have a field called
* "name" of type String, it will echo back the value "name". This is ONLY useful for mocking out a
* schema that do don't want to actually execute properly.
*/
@Internal
public class EchoingWiringFactory implements WiringFactory {
public static RuntimeWiring newEchoingWiring() {
return newEchoingWiring(x -> {
});
}
public static RuntimeWiring newEchoingWiring(Consumer builderConsumer) {
RuntimeWiring.Builder builder = RuntimeWiring.newRuntimeWiring();
builderConsumer.accept(builder);
return builder
.wiringFactory(new EchoingWiringFactory())
.build();
}
@Override
public boolean providesTypeResolver(InterfaceWiringEnvironment environment) {
return true;
}
@Override
public TypeResolver getTypeResolver(InterfaceWiringEnvironment environment) {
return env -> env.getSchema().getQueryType();
}
@Override
public boolean providesTypeResolver(UnionWiringEnvironment environment) {
return true;
}
@Override
public TypeResolver getTypeResolver(UnionWiringEnvironment environment) {
return env -> env.getSchema().getQueryType();
}
@Override
public DataFetcher getDefaultDataFetcher(FieldWiringEnvironment environment) {
return env -> {
GraphQLOutputType fieldType = env.getFieldType();
if (fieldType instanceof GraphQLObjectType) {
return fakeObjectValue((GraphQLObjectType) fieldType);
} else {
PropertyDataFetcher