.type(new GraphQLList(stoptimesInPatternType)) .argument(GraphQLArgument.newArgument() .name("date") .type(Scalars.GraphQLString) .build()) .dataFetcher(environment -> { try { // TODO: Add our own scalar types for at least serviceDate and FeedId .type(new GraphQLList(stoptimesInPatternType)) .argument(GraphQLArgument.newArgument() .name("startTime") .type(Scalars.GraphQLString) // No long exists in GraphQL .defaultValue("0") // Default value is current time .build()) .argument(GraphQLArgument.newArgument() .name("timeRange") .type(Scalars.GraphQLInt) .defaultValue(24 * 60 * 60) .build()) .argument(GraphQLArgument.newArgument() .name("numberOfDepartures") .type(Scalars.GraphQLInt) .defaultValue(5) .build()) .argument(GraphQLArgument.newArgument() .name("omitNonPickups") .type(Scalars.GraphQLBoolean) .defaultValue(false) .build())
private GraphQLArgument buildDirectiveArgument(Argument arg, Optional<GraphQLDirective> directiveDefinition) { Optional<GraphQLArgument> directiveDefArgument = directiveDefinition.map(dd -> dd.getArgument(arg.getName())); GraphQLArgument.Builder builder = GraphQLArgument.newArgument(); builder.name(arg.getName()); GraphQLInputType inputType; Object defaultValue = null; if (directiveDefArgument.isPresent()) { inputType = directiveDefArgument.get().getType(); defaultValue = directiveDefArgument.get().getDefaultValue(); } else { inputType = buildDirectiveInputType(arg.getValue()); } builder.type(inputType); builder.defaultValue(defaultValue); Object value = buildValue(arg.getValue(), inputType); // // we put the default value in if the specified is null builder.value(value == null ? defaultValue : value); return builder.build(); }
.type(profileResponseType) .argument(GraphQLArgument.newArgument() .name("fromLat") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("fromLon") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("toLat") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("toLon") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("fromTime") .type(GraphQLZonedDateTime) .description("The beginning of the departure window, in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM") .build()) .argument(GraphQLArgument.newArgument() .name("toTime") .type(GraphQLZonedDateTime) .description("The end of the departure window, in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM") .build())
.type(profileResponseType) .argument(GraphQLArgument.newArgument() .name("fromLat") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("fromLon") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("toLat") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("toLon") .type(new GraphQLNonNull(Scalars.GraphQLFloat)) .build()) .argument(GraphQLArgument.newArgument() .name("fromTime") .type(GraphQLZonedDateTime) .description("The beginning of the departure window, in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM") .build()) .argument(GraphQLArgument.newArgument() .name("toTime") .type(GraphQLZonedDateTime) .description("The end of the departure window, in ISO 8061 YYYY-MM-DDTHH:MM:SS+HH:MM") .build())
.name("validationStamps") .type(stdList(validationStamp.getTypeRef())) .argument(arg -> arg.name("name") .description("Filters on the validation stamp") .type(GraphQLString) .name("count") .description("Maximum number of builds to return") .type(GraphQLInt) .build() .name("lastPromotions") .description("Filter which returns the last promoted builds") .type(GraphQLBoolean) .build() .name("filter") .description("Filter based on build promotions, validations, properties, ...") .type(inputBuildStandardFilter.getTypeRef()) .build() .name("generic") .description("Generic filter based on a configured filter") .type(inputBuildGenericFilter.getTypeRef()) .build()
.name(ARGUMENT_OPERATION) .type(generator.classToEnumType(RelationshipOp.class)) .defaultValue(RelationshipOp.FETCH) .build(); .name(ARGUMENT_IDS) .type(new GraphQLList(Scalars.GraphQLString)) .build(); .name(ARGUMENT_FILTER) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_SORT) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_FIRST) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_AFTER) .type(Scalars.GraphQLString) .build();
.name(ARGUMENT_OPERATION) .type(generator.classToEnumType(RelationshipOp.class)) .defaultValue(RelationshipOp.FETCH) .build(); .name(ARGUMENT_IDS) .type(new GraphQLList(Scalars.GraphQLString)) .build(); .name(ARGUMENT_FILTER) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_SORT) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_FIRST) .type(Scalars.GraphQLString) .build(); .name(ARGUMENT_AFTER) .type(Scalars.GraphQLString) .build();
.type(droidType) .argument(GraphQLArgument.newArgument() .name("id") .description("id of the droid") .type(new GraphQLNonNull(Scalars.GraphQLString)) .build()) .build()) .build();
&& attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.BASIC) { arguments.add(GraphQLArgument.newArgument() .name(ORDER_BY_PARAM_NAME) .description("Specifies field sort direction in the query results.") .type(orderByDirectionEnum) .build() );
.argument( newArgument() .name("id") .description("ID of the build to look for") .type(GraphQLInt) .build() .name(PROJECT_ARGUMENT) .description("Name of a project") .type(GraphQLString) .build() .name(BRANCH_ARGUMENT) .description("Name of a branch - requires 'project' to be filled as well") .type(GraphQLString) .build() .name(BUILD_BRANCH_FILTER_ARGUMENT) .description("Filter to apply for the builds on the branch - requires 'branch' to be filled.") .type(inputBuildStandardFilter.getTypeRef()) .build() .name(BUILD_PROJECT_FILTER_ARGUMENT) .description("Filter to apply for the builds on the project - requires 'project' to be filled.") .type(inputBuildSearchForm.getTypeRef()) .build()
.name(QUERY_WHERE_PARAM_NAME) .description("Where logical specification") .type(whereInputObject) .build();
private void processMethodArguments(GraphQLFieldDefinition.Builder builder, IDataFetcher dataFetcher, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); int index = 0; for (Type paramType : method.getGenericParameterTypes()) { Optional<GraphQLParam> maybeGraphQLParam = Optional.fromNullable(AnnotationUtils.findAnnotation(parameterAnnotations[index], GraphQLParam.class)); Optional<GraphQLDescription> maybeGraphQLParamDesc = Optional.fromNullable(AnnotationUtils.findAnnotation(parameterAnnotations[index], GraphQLDescription.class)); if (!maybeGraphQLParam.isPresent()) { LOGGER.error("Missing @GraphParam annotation on parameter index {} for method {}", index, method.getName()); continue; } GraphQLParam graphQLParam = maybeGraphQLParam.get(); GraphQLInputType inputType = getInputType(paramType); if (graphQLParam.required()) { inputType = new GraphQLNonNull(inputType); } GraphQLArgument.Builder argBuilder = GraphQLArgument.newArgument().type(inputType).name(graphQLParam.name()); if (maybeGraphQLParamDesc.isPresent()) { argBuilder.description(maybeGraphQLParamDesc.get().value()); } if (!AnnotationUtils.isNullValue(graphQLParam.defaultValue())) { argBuilder.defaultValue(graphQLParam.defaultValue()); } builder.argument(argBuilder.build()); dataFetcher.addParam(graphQLParam.name(), paramType, Optional.<Object> fromNullable(AnnotationUtils.isNullValue(graphQLParam.defaultValue()) ? null : graphQLParam.defaultValue())); index++; } }
@Override public GraphQLFieldDefinition getFieldDefinition() { return newFieldDefinition() .name("accounts") .type(stdList(account.getTypeRef())) .argument( newArgument() .name(ID_ARGUMENT) .description("Searching by ID") .type(GraphQLInt) .build() ) .argument( newArgument() .name(NAME_ARGUMENT) .description("Searching by looking for a string in the name or the full name") .type(GraphQLString) .build() ) .argument( newArgument() .name(GROUP_ARGUMENT) .description("Searching by looking for a string in one of the groups the account belongs to") .type(GraphQLString) .build() ) .dataFetcher(adminAccountsFetcher()) .build(); }
@Override public List<GraphQLArgument> getConnectionFieldArguments() { List<GraphQLArgument> args = new ArrayList<>(); args.add(newArgument() .name("before") .description("fetching only nodes before this node (exclusive)") .type(GraphQLInt) .build()); args.add(newArgument() .name("after") .description("fetching only nodes after this node (exclusive)") .type(GraphQLInt) .build()); args.add(newArgument() .name("first") .description("fetching only the first certain number of nodes") .type(GraphQLInt) .build()); args.add(newArgument() .name("last") .description("fetching only the last certain number of nodes") .type(GraphQLInt) .build()); return args; } }
@Override public List<GraphQLFieldDefinition> getFields(Class<? extends ProjectEntity> projectEntityClass, ProjectEntityType projectEntityType) { return Collections.singletonList( newFieldDefinition() .name("properties") .description("List of properties") .argument( newArgument() .name("type") .description("Fully qualified name of the property type") .type(GraphQLString) .build() ) .argument( newArgument() .name("hasValue") .description("Keeps properties having a value") .type(GraphQLBoolean) .defaultValue(false) .build() ) .type(GraphqlUtils.stdList(property.getTypeRef())) .dataFetcher(projectEntityPropertiesDataFetcher(projectEntityClass)) .build() ); }
public List<GraphQLArgument> getConnectionFieldArguments() { List<GraphQLArgument> args = new ArrayList<>(); args.add(newArgument() .name("before") .description("fetching only nodes before this node (exclusive)") .type(GraphQLString) .build()); args.add(newArgument() .name("after") .description("fetching only nodes after this node (exclusive)") .type(GraphQLString) .build()); args.add(newArgument() .name("first") .description("fetching only the first certain number of nodes") .type(GraphQLInt) .build()); args.add(newArgument() .name("last") .description("fetching only the last certain number of nodes") .type(GraphQLInt) .build()); return args; }
@Override public List<GraphQLFieldDefinition> getFields( Class<? extends ProjectEntity> projectEntityClass, ProjectEntityType projectEntityType) { if (projectEntityType == ProjectEntityType.PROJECT) { return Collections.singletonList( GraphQLFieldDefinition.newFieldDefinition() .name("projectRoles") .description("Authorisations for the project") .type(stdList(projectAuthorization.getTypeRef())) .argument(a -> a.name("role") .description("Filter by role name") .type(GraphQLString) ) .dataFetcher(projectAuthorizationsFetcher()) .build() ); } else { return Collections.emptyList(); } }
protected GraphQLArgument getArgument(Parameter parameter, graphql.schema.GraphQLType t) throws GraphQLAnnotationsException { GraphQLArgument.Builder builder = newArgument(); builder.type(parameter.getAnnotation(NotNull.class) == null ? (GraphQLInputType) t : new graphql.schema.GraphQLNonNull(t)); GraphQLDescription description = parameter.getAnnotation(GraphQLDescription.class); if (description != null) { builder.description(description.value()); } GraphQLDefaultValue defaultValue = parameter.getAnnotation(GraphQLDefaultValue.class); if (defaultValue != null) { builder.defaultValue(newInstance(defaultValue.value()).get()); } GraphQLName name = parameter.getAnnotation(GraphQLName.class); if (name != null) { builder.name(toGraphqlName(name.value())); } else { builder.name(toGraphqlName(parameter.getName())); } return builder.build(); }
private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) { buildCtx.enterNode(valueDefinition); GraphQLArgument.Builder builder = GraphQLArgument.newArgument(); builder.definition(valueDefinition); builder.name(valueDefinition.getName()); builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription())); GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType()); builder.type(inputType); Value defaultValue = valueDefinition.getDefaultValue(); if (defaultValue != null) { builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType)); } builder.withDirectives( buildDirectives(valueDefinition.getDirectives(), emptyList(), ARGUMENT_DEFINITION, buildCtx.getDirectiveDefinitions()) ); GraphQLArgument argument = builder.build(); argument = directiveBehaviour.onArgument(argument, buildCtx.mkBehaviourParams()); return buildCtx.exitNode(argument); }
@Test public void optionalInput() { GraphQLObjectType object = GraphQLAnnotations.object(OptionalTest.class); GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); GraphQLInputObjectType inputObject = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). getInputObjectBuilder(OptionalTest.class, GraphQLAnnotations.getInstance().getContainer()).build(); GraphQLObjectType mutation = GraphQLObjectType.newObject().name("mut").field(newFieldDefinition().name("test").type(object). argument(GraphQLArgument.newArgument().type(inputObject).name("input").build()).dataFetcher(environment -> { Map<String, String> input = environment.getArgument("input"); return new OptionalTest(Optional.ofNullable(input.get("empty")), Optional.ofNullable(input.get("nonempty"))); }).build()).build(); GraphQLSchema schema = newSchema().query(object).mutation(mutation).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).build(); ExecutionResult result = graphQL.execute("mutation {test(input: {empty: \"test\"}) { empty nonempty } }", new OptionalTest()); assertTrue(result.getErrors().isEmpty()); Map<String, Object> v = (Map<String, Object>) ((Map<String, Object>) result.getData()).get("test"); assertEquals(v.get("empty"), "test"); assertNull(v.get("nonempty")); }