use of graphql.execution.DataFetcherResult in project teamcity-rest by JetBrains.
the class Mutation method assignBuildTypeWithAgent.
@Used("graphql")
@NotNull
public DataFetcherResult<AssignBuildTypeWithAgentPayload> assignBuildTypeWithAgent(@NotNull AssignBuildTypeWithAgentInput input) {
return runWithAgent(input.getAgentRawId(), agent -> {
DataFetcherResult.Builder<AssignBuildTypeWithAgentPayload> result = DataFetcherResult.newResult();
SBuildType bt = myBuildTypeFinder.getItem("id:" + input.getBuildTypeRawId()).getBuildType();
if (bt == null) {
final String errorMessage = String.format("Build type with id=%s is not found.", input.getBuildTypeRawId());
return result.error(new EntityNotFoundGraphQLError(errorMessage)).build();
}
myAgentTypeManager.includeRunConfigurationsToAllowed(agent.getAgentTypeId(), new String[] { bt.getInternalId() });
return result.data(new AssignBuildTypeWithAgentPayload(new Agent(agent), new BuildType(bt))).build();
});
}
use of graphql.execution.DataFetcherResult in project teamcity-rest by JetBrains.
the class Mutation method authorizeAgent.
@Used("graphql")
@NotNull
public DataFetcherResult<AuthorizeAgentPayload> authorizeAgent(@NotNull AuthorizeAgentInput input, @NotNull DataFetchingEnvironment dfe) {
return runWithAgent(input.getAgentRawId(), agent -> {
DataFetcherResult.Builder<AuthorizeAgentPayload> result = DataFetcherResult.newResult();
GraphQLContext context = dfe.getContext();
String authReason = input.getReason() == null ? "" : input.getReason();
// Move agent to another pool first as we don't want some cheeky build to start while agent is in a wrong pool.
if (input.getTargetAgentPoolRawId() != null) {
try {
myAgentPoolManager.moveAgentToPool(input.getTargetAgentPoolRawId(), agent);
} catch (NoSuchAgentPoolException e) {
return result.error(new EntityNotFoundGraphQLError(String.format("Agent pool with id=%d is not found.", input.getTargetAgentPoolRawId()))).build();
} catch (PoolQuotaExceededException e) {
LOG.debug(e.getMessage());
return result.error(new OperationFailedGraphQLError(String.format("Agent pool with id=%d does not accept agents.", input.getTargetAgentPoolRawId()))).build();
} catch (AgentTypeCannotBeMovedException e) {
LOG.debug(e.getMessage());
return result.error(new OperationFailedGraphQLError(String.format("Agent with id=%d can not be moved.", input.getAgentRawId()))).build();
}
}
agent.setAuthorized(true, context.getUser(), authReason);
Agent agentModel = new Agent(agent);
AbstractAgentPool targetPoolModel = null;
if (input.getTargetAgentPoolRawId() != null) {
AgentPool realPool = myAgentPoolManager.findAgentPoolById(input.getTargetAgentPoolRawId());
if (realPool != null) {
targetPoolModel = myAgentPoolFactory.produce(realPool);
}
}
return result.data(new AuthorizeAgentPayload(agentModel, targetPoolModel)).build();
});
}
use of graphql.execution.DataFetcherResult in project stargate by stargate.
the class UpdateFetcher method getPayload.
@Override
protected MutationPayload<DataFetcherResult<Object>> getPayload(DataFetchingEnvironment environment, StargateGraphqlContext context) throws UnauthorizedException {
DataFetchingFieldSelectionSet selectionSet = environment.getSelectionSet();
EntityModel entityModel = model.getEntity();
Keyspace keyspace = context.getDataStore().schema().keyspace(entityModel.getKeyspaceName());
// We're either getting the values from a single entity argument, or individual PK field
// arguments:
Predicate<String> hasArgument;
Function<String, Object> getArgument;
if (model.getEntityArgumentName().isPresent()) {
Map<String, Object> entity = environment.getArgument(model.getEntityArgumentName().get());
hasArgument = entity::containsKey;
getArgument = entity::get;
} else {
hasArgument = environment::containsArgument;
getArgument = environment::getArgument;
}
List<BuiltCondition> whereConditions = bindWhere(model.getWhereConditions(), hasArgument, getArgument, entityModel::validateForUpdate, keyspace);
List<BuiltCondition> ifConditions = bindIf(model.getIfConditions(), hasArgument, getArgument, keyspace);
Collection<ValueModifier> modifiers;
if (!model.getIncrementModels().isEmpty()) {
modifiers = buildIncrementModifiers(model.getIncrementModels(), keyspace, hasArgument, getArgument);
} else {
modifiers = buildModifiers(entityModel, keyspace, hasArgument, getArgument);
}
// we are supporting BigInt and GraphQLString for ISO date format
Optional<Long> timestamp = TimestampParser.parse(model.getCqlTimestampArgumentName(), environment);
AbstractBound<?> query = buildUpdateQuery(entityModel, modifiers, whereConditions, ifConditions, timestamp, context);
List<TypedKeyValue> primaryKey = TypedKeyValue.forDML((BoundDMLQuery) query);
authorizeUpdate(entityModel, primaryKey, context);
Function<List<MutationResult>, DataFetcherResult<Object>> resultBuilder = getDeleteOrUpdateResultBuilder(environment);
return new MutationPayload<>(query, primaryKey, resultBuilder);
}
use of graphql.execution.DataFetcherResult in project graphql-orchestrator-java by intuit.
the class BatchResultTransformerTest method defaultBatchTransformerBatchResultWithError.
@Test
public void defaultBatchTransformerBatchResultWithError() {
batchResults.put("field1", "value1");
GraphQLError error = GraphqlErrorBuilder.newError().message("boom").build();
final DataFetchingEnvironment dataFetchingEnvironment = DataFetchingEnvironmentImpl.newDataFetchingEnvironment().mergedField(newMergedField().addField(newField("field1").build()).build()).build();
environments.add(dataFetchingEnvironment);
dataFetcherResult = DataFetcherResult.<Map<String, Object>>newResult().data(batchResults).error(error).build();
final List<DataFetcherResult<Object>> results = batchResultTransformer.toBatchResult(dataFetcherResult, environments);
assertThat(results).hasSize(1).extracting(DataFetcherResult::getData).containsOnly("value1");
assertThat(results).flatExtracting(DataFetcherResult::getErrors).containsOnly(error);
}
use of graphql.execution.DataFetcherResult in project graphql-orchestrator-java by intuit.
the class BatchResultTransformerTest method defaultBatchTransformerWithMatchingPathError.
@Test
public void defaultBatchTransformerWithMatchingPathError() {
final DataFetchingEnvironment environment = DataFetchingEnvironmentImpl.newDataFetchingEnvironment().mergedField(newMergedField().addField(newField("field1").build()).build()).build();
environments.add(environment);
GraphQLError correctError = GraphqlErrorBuilder.newError().message("boom").path(Arrays.asList("field1", 1, 2)).build();
final GraphQLError shouldBeIgnoredError = GraphqlErrorBuilder.newError().message("boom").path(Arrays.asList("field2", 1, 2)).build();
dataFetcherResult = DataFetcherResult.<Map<String, Object>>newResult().data(batchResults).error(correctError).error(shouldBeIgnoredError).build();
final List<DataFetcherResult<Object>> results = batchResultTransformer.toBatchResult(dataFetcherResult, environments);
assertThat(results).hasSize(1).flatExtracting(DataFetcherResult::getErrors).containsOnly(correctError).doesNotContain(shouldBeIgnoredError);
}
Aggregations