@Override public Object get(DataFetchingEnvironment environment) { Object targetMethodResult = null; try { beforeInvocation(environment); Object[] bindByClassValues = collectBindByClassValues(environment); Object[] inputArguments = getMethodParametersBinder().bindParameters(unwrapInputArguments(environment), bindByClassValues); targetMethodResult = getTargetMethod().invoke(getTargetObject(), inputArguments); targetMethodResult = afterInvocation(environment, targetMethodResult); } catch (Exception e) { String msg = "Exception while calling data fetcher [" + getTargetMethod().getName() + "]"; if (LOGGER.isErrorEnabled()) LOGGER.error(msg, e); throw new DataMutatorRuntimeException(msg, e); } return targetMethodResult; }
protected Object afterInvocation(DataFetchingEnvironment environment, Object targetMethodResult) { Map<String, Object> inputMap = unwrapInputArguments(environment); Map<String, Object> outputMap = new HashMap<>(); outputMap.put(getGraphQLMethodParameters().getReturnTypeName(), targetMethodResult); injectClientMutationIdIfRequired(inputMap, outputMap); return outputMap; }
private void injectClientMutationIdIfRequired(Map<String, Object> inputMap, Map<String, Object> outputMap) { if (getGraphQLSchemaConfig().isInjectClientMutationId()) { String clientMutationId = (String) inputMap.get(getGraphQLSchemaConfig().getClientMutationIdName()); outputMap.put(getGraphQLSchemaConfig().getClientMutationIdName(), clientMutationId); } }
.deprecate(methodReturnTypeResolvableTypeAccessor.getGraphQLDeprecationReason()) .type(graphQLOutputObjectType) .dataFetcher(new ReflectionGraphQLDataMutator(graphQLSchemaConfig, object, method));
protected Map<String, Object> unwrapInputArguments(DataFetchingEnvironment environment) { Map<String, Object> inputObject = null; String inArgName = getGraphQLSchemaConfig().getMutationInputArgumentName(); if (environment.getArguments() != null && (environment.getArguments() instanceof Map)) { inputObject = (Map<String, Object>) environment.getArguments().get(inArgName); } return inputObject; }