All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prompto.graphql.GraphQLAttributeFetcher Maven / Gradle / Ivy

There is a newer version: 0.1.57
Show newest version
package prompto.graphql;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import prompto.grammar.Identifier;
import prompto.runtime.ApplicationContext;
import prompto.value.ConcreteInstance;

public class GraphQLAttributeFetcher implements DataFetcher {

	Identifier attribute;
	
	public GraphQLAttributeFetcher(Identifier attribute) {
		this.attribute = attribute;
	}

	@Override
	public Object get(DataFetchingEnvironment environment) throws Exception {
		Object instance = environment.getSource();
		if(instance instanceof ConcreteInstance)
			return ((ConcreteInstance)instance).getMember(ApplicationContext.get(), attribute, false);
		else
			return null;
	}

}