当前位置: 首页>>代码示例>>Java>>正文


Java DataFetchingEnvironment类代码示例

本文整理汇总了Java中graphql.schema.DataFetchingEnvironment的典型用法代码示例。如果您正苦于以下问题:Java DataFetchingEnvironment类的具体用法?Java DataFetchingEnvironment怎么用?Java DataFetchingEnvironment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DataFetchingEnvironment类属于graphql.schema包,在下文中一共展示了DataFetchingEnvironment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
public Customer get(DataFetchingEnvironment environment) {
    Map arguments = environment.getArguments();
    Customer customer = new Customer();
    if(arguments.get("id") != null){
        customer.setId(Long.parseLong(arguments.get("id").toString()));
    }
    customer.setFirstName(arguments.get("firstName").toString());
    customer.setLastName(arguments.get("lastName").toString());

    if(arguments.get("accounts") != null){
        ArrayList array = (ArrayList) arguments.get("accounts");
        for(Object o: array){
            Map m = (Map)o;
            String accountName = m.get("accountName").toString();
        }
    }

    customer = customerRepository.save(customer);
    return customer;
}
 
开发者ID:rylitalo,项目名称:graphql-with-springboot-jpa-example,代码行数:22,代码来源:SaveCustomerDataFetcher.java

示例2: sayHello

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Query("sayHello")
HelloReply sayHello(
    HelloRequest request,
    StreamingGreeterGrpc.StreamingGreeterStub client,
    DataFetchingEnvironment dataFetchingEnvironment) {
  client.sayHelloStreaming(
      request,
      new GraphQlStreamObserver<HelloReply, GraphQlResponse>(dataFetchingEnvironment) {
        @Override
        protected GraphQlResponse getData(HelloReply value, ListValue path) {
          // TODO: how can this be improved?
          QueryType data =
              QueryType.newBuilder()
                  .setHelloReply(
                      io.grpc.examples.graphql.HelloReply.newBuilder()
                          .setMessage(value.getMessage())
                          .build())
                  .build();

          return GraphQlResponse.newBuilder().setPath(path).setData(data).build();
        }
      });

  return null;
}
 
开发者ID:google,项目名称:rejoiner,代码行数:26,代码来源:HelloWorldSchemaModule.java

示例3: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
  Object source = environment.getSource();
  if (source == null) {
    return null;
  }
  if (source instanceof Map) {
    return ((Map<?, ?>) source).get(name);
  }
  GraphQLType type = environment.getFieldType();
  if (type instanceof GraphQLNonNull) {
    type = ((GraphQLNonNull) type).getWrappedType();
  }
  if (type instanceof GraphQLList) {
    return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name) + "List");
  }
  if (type instanceof GraphQLEnumType) {
    Object o = call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
    if (o != null) {
      return o.toString();
    }
  }

  return call(source, "get" + LOWER_CAMEL_TO_UPPER.convert(name));
}
 
开发者ID:google,项目名称:rejoiner,代码行数:26,代码来源:ProtoToGql.java

示例4: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {

    @SuppressWarnings("unchecked")
    Object idObject = ((Map<String, Object>) environment.getSource()).get(memberFieldName);
    String id = Optional.ofNullable(idObject).map(Object::toString).orElse(null);
    if (id == null) {
        return null;
    }

    SchemaInstanceKey parentSchemaInstanceKey =
            ((GraphQLInstanceRequestContext) environment.getContext()).getSchemaInstanceKey();

    SchemaInstanceKey schemaInstanceKey = parentSchemaInstanceKey.getChildSchemaInstanceKey(schemaName);

    GraphQLInstanceRequestContext context = environment.getContext();

    return CacheService.getSchemaInstance(schemaInstanceKey, id, context, instanceOutputTypeService);
}
 
开发者ID:nfl,项目名称:gold,代码行数:20,代码来源:DataFetcherFactory.java

示例5: fetchDataImpl

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
Object fetchDataImpl(DataFetchingEnvironment environment, Map<String, Object> mapEntry) {
    @SuppressWarnings("unchecked")
    String schemaName = ((Map<String, String>)mapEntry.get(SchemaInstance.SCHEMA_INSTANCE_KEY_FIELD))
            .get(BaseKey.SCHEMA_NAME_FIELD);
    SchemaInstanceKey parentSchemaInstanceKey =
            ((GraphQLInstanceRequestContext) environment.getContext()).getSchemaInstanceKey();

    SchemaInstanceKey schemaInstanceKey = parentSchemaInstanceKey.getChildSchemaInstanceKey(schemaName);
    SchemaInstance retMap = schemaInstanceRepository.findById(schemaInstanceKey,
            (String)mapEntry.get(REFERENCE_ID));
    if (retMap == null) {
        return null;
    }
    // Helper field to do type resolution in the type resolver
    retMap.put(TYPE_NAME_DECORATOR, schemaName);
    return retMap;
}
 
开发者ID:nfl,项目名称:gold,代码行数:18,代码来源:DataFetcherFactory.java

示例6: fetchParameters

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
private Object[] fetchParameters(Method m, DataFetchingEnvironment env) {
	Parameter[] params = m.getParameters();
	Object[] args = new Object[params.length];
	for (int i = 0;i < args.length;i++) {
		String argName = params[i].getName();
		Object arg = null;
		if (params[i].isAnnotationPresent(GraphQLParam.class)) {
			argName = params[i].getAnnotation(GraphQLParam.class).value();
			arg = env.getArgument(argName);
		} else if (params[i].isAnnotationPresent(DefaultValue.class)) {
			arg = params[i].getAnnotation(DefaultValue.class).value();
		}
		if (arg == null) { return null; }
		args[i] = arg;
	}
	return args;
}
 
开发者ID:deptofdefense,项目名称:anet,代码行数:18,代码来源:PropertyDataFetcherWithArgs.java

示例7: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {

	for (Field field : environment.getFields()) {
		if (field.getName().equals(fieldName)) {
			Object[] arguments = new Object[argumentTypeMap.size()];
			int index = 0;
			for (String argumentName : argumentTypeMap.keySet()) {
				arguments[index] = getParamValue(environment, argumentName, argumentTypeMap.get(argumentName));
				index++;
			}
			return invokeMethod(environment, method, targetObject.isPresent() ? targetObject.get() : environment.getSource(), arguments);
		}
	}
	return null;

}
 
开发者ID:bpatters,项目名称:schemagen-graphql,代码行数:18,代码来源:DefaultMethodDataFetcher.java

示例8: ResolverDataFetcher

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
public ResolverDataFetcher(DataFetcher fetcher, Resolver resolver, int listDepth) {
    this.fetcher = fetcher;
    this.resolver = resolver;
    this.listDepth = listDepth;
    if ( fetcher instanceof BatchedDataFetcher ) {
        this.isBatched = true;
    } else {
        try {
            Method getMethod = fetcher.getClass()
                .getMethod("get", DataFetchingEnvironment.class);
            this.isBatched = null != getMethod.getAnnotation(Batched.class);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException(e);
        }
    }
}
 
开发者ID:Distelli,项目名称:graphql-apigen,代码行数:17,代码来源:ResolverDataFetcher.java

示例9: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Batched
@Override
public Object get(DataFetchingEnvironment env) {
    List<Object> unresolved = new ArrayList<>();
    Object result;
    int depth = listDepth;
    if ( env.getSource() instanceof List ) { // batched.
        result = getBatched(env);
        if ( null != resolver ) addUnresolved(unresolved, result, ++depth);
    } else {
        result = getUnbatched(env);
        if ( null != resolver ) addUnresolved(unresolved, result, depth);
    }
    if ( null == resolver ) return result;
    return replaceResolved(result, resolver.resolve(unresolved).iterator(), depth);
}
 
开发者ID:Distelli,项目名称:graphql-apigen,代码行数:17,代码来源:ResolverDataFetcher.java

示例10: getUnbatched

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
public Object getUnbatched(DataFetchingEnvironment env) {
    if ( ! isBatched ) return fetcher.get(env);
    DataFetchingEnvironment envCopy =
        new DataFetchingEnvironmentImpl(
            Collections.singletonList(env.getSource()),
            env.getArguments(),
            env.getContext(),
            env.getFields(),
            env.getFieldType(),
            env.getParentType(),
            env.getGraphQLSchema(),
                env.getFragmentsByName(),
                env.getExecutionId(),
                env.getSelectionSet());
    Object result = fetcher.get(envCopy);
    if ( !(result instanceof List) || ((List)result).size() != 1 ) {
        throw new IllegalStateException("Batched fetcher "+fetcher+" expected to return list of 1");
    }
    return ((List)result).get(0);
}
 
开发者ID:Distelli,项目名称:graphql-apigen,代码行数:21,代码来源:ResolverDataFetcher.java

示例11: isDataFetcherBatched

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
/**
 * Tells whether a given data fetcher supports batching
 *  {code @Batched} on the get method or instance of {code BatchedDataFetcher}
 *
 * @param supplied data fetcher
 * @return true if batched, false otherwise
 */
public static boolean isDataFetcherBatched(DataFetcher supplied) {
    if (supplied instanceof BatchedDataFetcher) {
        return true;
    }

    try {
        Method getMethod = supplied.getClass().getMethod("get", DataFetchingEnvironment.class);
        Batched batched = getMethod.getAnnotation(Batched.class);
        if (batched != null) {
            return true;
        }
    } catch (NoSuchMethodException e) {
        throw new IllegalArgumentException(e);
    }
    return false;
}
 
开发者ID:nfl,项目名称:glitr,代码行数:24,代码来源:ReflectionUtil.java

示例12: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object get(DataFetchingEnvironment env) {
    Map<String, Object> inputMap = env.getArgument("input");

    // map fields from input map to mutationInputClass
    Object inputPayloadMtn = Glitr.getObjectMapper().convertValue(inputMap, mutationInputClass);
    // apply some validation on inputPayloadMtn (should validation be in the mutationFunc instead?)
    validate(inputPayloadMtn);
    // mutate and return output
    RelayMutationType mutationOutput = mutationFunc.call((RelayMutationType) inputPayloadMtn, env);
    // set the client mutation id
    mutationOutput.setClientMutationId((String) inputMap.get("clientMutationId"));

    return mutationOutput;
}
 
开发者ID:nfl,项目名称:glitr,代码行数:17,代码来源:RelayMutationDataFetcher.java

示例13: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@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;
}
 
开发者ID:oembedler,项目名称:spring-graphql-common,代码行数:23,代码来源:ReflectionGraphQLDataMutator.java

示例14: get

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
@Override
public Object get(DataFetchingEnvironment environment) {
    Object targetMethodResult = null;
    try {

        beforeInvocation(environment);

        Object[] bindByClassValues = collectBindByClassValues(environment);
        Object[] inputArguments = getMethodParametersBinder().bindParameters(environment.getArguments(), bindByClassValues);
        if (isAllNulls(inputArguments) && canApplySourceObject(environment)) {
            inputArguments = new Object[]{environment.getSource()};
        }
        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 DataFetcherRuntimeException(msg, e);
    }

    return targetMethodResult;
}
 
开发者ID:oembedler,项目名称:spring-graphql-common,代码行数:26,代码来源:ReflectionGraphQLDataFetcher.java

示例15: handleUuidNameArgsNoPerm

import graphql.schema.DataFetchingEnvironment; //导入依赖的package包/类
/**
 * Handle the UUID or name arguments and locate and return the vertex by the given functions.
 *
 * @param env
 * @param uuidFetcher
 * @param nameFetcher
 * @return
 */
protected MeshCoreVertex<?, ?> handleUuidNameArgsNoPerm(DataFetchingEnvironment env, Function<String, MeshCoreVertex<?, ?>> uuidFetcher,
		Function<String, MeshCoreVertex<?, ?>> nameFetcher) {
	String uuid = env.getArgument("uuid");
	MeshCoreVertex<?, ?> element = null;
	if (uuid != null) {
		element = uuidFetcher.apply(uuid);
	}
	String name = env.getArgument("name");
	if (name != null) {
		element = nameFetcher.apply(name);
	}
	if (element == null) {
		return null;
	}

	return element;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:26,代码来源:AbstractTypeProvider.java


注:本文中的graphql.schema.DataFetchingEnvironment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。