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


Java DataFetchingEnvironment.getContext方法代码示例

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


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

示例1: 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

示例2: 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

示例3: parentNodeFetcher

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
 * Fetcher for the parent node reference of a node.
 * 
 * @param env
 * @return
 */
public Object parentNodeFetcher(DataFetchingEnvironment env) {
	NodeContent content = env.getSource();
	if (content == null) {
		return null;
	}
	GraphQLContext gc = env.getContext();
	String uuid = gc.getRelease().getUuid();
	Node parentNode = content.getNode().getParentNode(uuid);
	// The project root node can have no parent. Lets check this and exit early.
	if (parentNode == null) {
		return null;
	}
	gc.requiresPerm(parentNode, READ_PERM, READ_PUBLISHED_PERM);
	return handleLanguageFallback(gc, parentNode, content);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:22,代码来源:NodeTypeProvider.java

示例4: nodeLanguageFetcher

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public Object nodeLanguageFetcher(DataFetchingEnvironment env) {
	NodeContent content = env.getSource();
	if (content == null) {
		return null;
	}
	List<String> languageTags = getLanguageArgument(env);
	GraphQLContext gc = env.getContext();

	Node node = content.getNode();
	Release release = gc.getRelease();
	NodeGraphFieldContainer container = node.findVersion(gc, languageTags);
	// There might not be a container for the selected language (incl. fallback language)
	if (container == null) {
		return null;
	}

	// Check whether the user is allowed to read the published container
	boolean isPublished = container.isPublished(release.getUuid());
	if (isPublished) {
		gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM);
	} else {
		// Otherwise the container is a draft and we need to use the regular read permission
		gc.requiresPerm(node, READ_PERM);
	}
	return new NodeContent(node, container);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:27,代码来源:NodeTypeProvider.java

示例5: createLink

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public Link createLink(String url, String description, DataFetchingEnvironment env) {
	AuthContext context = env.getContext();
	if (context.getUser() == null || context.getUser().getId() == null) {
		throw new GraphQLException("Only a loggedin user can create a link");
	}
	Link newLink = new Link(url, description, context.getUser().getId());
	newLink = linkRepository.save(newLink);
	return newLink;
}
 
开发者ID:thekosmix,项目名称:GraphQL-SpringBoot,代码行数:10,代码来源:Mutation.java

示例6: get

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
@Override
public List<UserDto> get(DataFetchingEnvironment environment) {
    HttpHeaders headers = environment.getContext();
    log.info("getContext() {}", headers);
    log.info("getArguments {}", environment.getArguments());
    List<UserDto> allUsers = userAdaptor.getAllUsers();
    return allUsers;
}
 
开发者ID:roybailey,项目名称:research-graphql,代码行数:9,代码来源:UserListFetcher.java

示例7: FetchParams

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public FetchParams(DataFetchingEnvironment environment, HGQLSchema hgqlschema) {

        subjectResource = environment.getSource();
        String predicate = ((Field) environment.getFields().toArray()[0]).getName();
        predicateURI = hgqlschema.getFields().get(predicate).getId();
        client = environment.getContext();
        if (!environment.getParentType().getName().equals("Query")) {
            String targetName = hgqlschema.getTypes().get(environment.getParentType().getName()).getField(predicate).getTargetName();
            if (hgqlschema.getTypes().containsKey(targetName) && hgqlschema.getTypes().get(targetName).getId()!=null) {
                targetURI=hgqlschema.getTypes().get(targetName).getId();
            }
        }
    }
 
开发者ID:semantic-integration,项目名称:hypergraphql,代码行数:14,代码来源:FetchParams.java

示例8: execute

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public Object execute(DataFetchingEnvironment env) {
    Resolver resolver;
    if (env.getContext() instanceof ContextWrapper) {
        ContextWrapper context = env.getContext();
        if (env.getArguments().get("clientMutationId") != null) {
            context.putExtension("clientMutationId", env.getArguments().get("clientMutationId"));
        }
    }

    if (this.operation.getResolvers().size() == 1) {
        resolver = this.operation.getResolvers().iterator().next();
    } else {
        String[] nonNullArgumentNames = env.getArguments().entrySet().stream()
                .filter(arg -> arg.getValue() != null)
                .map(Map.Entry::getKey)
                .toArray(String[]::new);

        resolver = this.operation.getResolver(nonNullArgumentNames);
        if (resolver == null) {
            throw new GraphQLException("Resolver for operation " + operation.getName() + " accepting arguments: "
                    + Arrays.toString(nonNullArgumentNames) + " not implemented");
        }
    }
    ResolutionEnvironment resolutionEnvironment = new ResolutionEnvironment(env, this.valueMapper, this.globalEnvironment);
    try {
        Object result = execute(resolver, resolutionEnvironment, env.getArguments());
        return resolutionEnvironment.convertOutput(result, resolver.getReturnType());
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:32,代码来源:OperationExecutor.java

示例9: ResolutionEnvironment

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
public ResolutionEnvironment(DataFetchingEnvironment env, ValueMapper valueMapper, GlobalEnvironment globalEnvironment) {
    
    this.context = env.getSource();
    this.rootContext = env.getContext();
    this.valueMapper = valueMapper;
    this.globalEnvironment = globalEnvironment;
    this.fields = env.getFields();
    this.fieldType = env.getFieldType();
    this.parentType = env.getParentType();
    this.graphQLSchema = env.getGraphQLSchema();
    this.dataFetchingEnvironment = env;
}
 
开发者ID:leangen,项目名称:graphql-spqr,代码行数:13,代码来源:ResolutionEnvironment.java

示例10: userMeFetcher

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
 * Data fetcher for the currently active user.
 * 
 * @param env
 * @return
 */
public Object userMeFetcher(DataFetchingEnvironment env) {
	GraphQLContext gc = env.getContext();
	User requestUser = gc.getUser();
	// No need to check for permissions. The user should always be able to read himself
	return requestUser;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:13,代码来源:QueryTypeProvider.java

示例11: rootNodeFetcher

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
 * Data fetcher for the root node of the current project.
 * 
 * @param env
 * @return
 */
public Object rootNodeFetcher(DataFetchingEnvironment env) {
	GraphQLContext gc = env.getContext();
	Project project = gc.getProject();
	if (project != null) {
		Node node = project.getBaseNode();
		gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM);
		NodeGraphFieldContainer container = node.findVersion(gc, getLanguageArgument(env));
		return new NodeContent(node, container);
	}
	return null;
}
 
开发者ID:gentics,项目名称:mesh,代码行数:18,代码来源:QueryTypeProvider.java

示例12: handleUuidNameArgs

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
 * Handle the UUID or name arguments and locate and return the vertex from the root vertex.
 * 
 * @param env
 * @param root
 * @return
 */
protected MeshVertex handleUuidNameArgs(DataFetchingEnvironment env, RootVertex<?> root) {
	GraphQLContext gc = env.getContext();
	MeshCoreVertex<?, ?> element = handleUuidNameArgsNoPerm(env, root::findByUuid, root::findByName);
	if (element == null) {
		return null;
	} else {
		return gc.requiresPerm(element, READ_PERM);
	}
}
 
开发者ID:gentics,项目名称:mesh,代码行数:17,代码来源:AbstractTypeProvider.java

示例13: handleReleaseSchema

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
protected MeshVertex handleReleaseSchema(DataFetchingEnvironment env) {
	GraphQLContext gc = env.getContext();
	Release release = env.getSource();
	Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(release.findActiveSchemaVersions().spliterator(), false);

	// We need to handle permissions dedicately since we check the schema container perm and not the schema container version perm.
	return handleUuidNameArgsNoPerm(env, uuid -> schemas.filter(schema -> {
		SchemaContainer container = schema.getSchemaContainer();
		return container.getUuid().equals(uuid) && gc.getUser().hasPermission(container, READ_PERM);
	}).findFirst().get(), name -> schemas.filter(schema -> schema.getName().equals(name) && gc.getUser().hasPermission(schema
			.getSchemaContainer(), READ_PERM)).findFirst().get());
}
 
开发者ID:gentics,项目名称:mesh,代码行数:13,代码来源:AbstractTypeProvider.java

示例14: handleReleaseSchemas

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
protected Page<SchemaContainerVersion> handleReleaseSchemas(DataFetchingEnvironment env) {
	GraphQLContext gc = env.getContext();
	Release release = env.getSource();
	Stream<? extends SchemaContainerVersion> schemas = StreamSupport.stream(release.findActiveSchemaVersions().spliterator(), false).filter(
			schema -> gc.getUser().hasPermission(schema.getSchemaContainer(), READ_PERM));
	return new DynamicStreamPageImpl<>(schemas, getPagingInfo(env));
}
 
开发者ID:gentics,项目名称:mesh,代码行数:8,代码来源:AbstractTypeProvider.java

示例15: baseNodeFetcher

import graphql.schema.DataFetchingEnvironment; //导入方法依赖的package包/类
/**
 * Fetcher for the project base node.
 * 
 * @param env
 * @return
 */
private NodeContent baseNodeFetcher(DataFetchingEnvironment env) {
	GraphQLContext gc = env.getContext();
	Project project = env.getSource();
	Node node = project.getBaseNode();
	gc.requiresPerm(node, READ_PERM, READ_PUBLISHED_PERM);
	NodeGraphFieldContainer container = node.findVersion(gc, getLanguageArgument(env));
	return new NodeContent(node, container);
}
 
开发者ID:gentics,项目名称:mesh,代码行数:15,代码来源:ProjectTypeProvider.java


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