/** * This helps you transform the current GraphQLArgument into another one by starting a builder with all * the current values and allows you to transform it how you want. * * @param builderConsumer the consumer code that will be given a builder to transform * * @return a new field based on calling build on that builder */ public GraphQLArgument transform(Consumer<Builder> builderConsumer) { Builder builder = newArgument(this); builderConsumer.accept(builder); return builder.build(); }
public List<GraphQLArgument> getBackwardPaginationConnectionFieldArguments() { 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("last") .description("fetching only the last certain number of nodes") .type(GraphQLInt) .build()); return args; }
public List<GraphQLArgument> getForwardPaginationConnectionFieldArguments() { List<GraphQLArgument> args = new ArrayList<>(); 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()); return args; }
public static GraphQLArgument intArg (String name) { return newArgument() .name(name) .type(GraphQLInt) .build(); }
private GraphQLArgument getArgument(Attribute<?,?> attribute) { GraphQLType type = getAttributeType(attribute); String description = getSchemaDescription(attribute.getJavaMember()); if (type instanceof GraphQLInputType) { return GraphQLArgument.newArgument() .name(attribute.getName()) .type((GraphQLInputType) type) .description(description) .build(); } throw new IllegalArgumentException("Attribute " + attribute + " cannot be mapped as an Input Argument"); }
public GraphQLArgument getArgument(Field field, Class<?> containingClass) { GraphQLArgument.Builder builder = newArgument() .name(commonPropertiesCreator.getName(field)) .description(commonPropertiesCreator.getDescription(field)) .type(getType(field)); try { builder.defaultValue(getDefaultValue(field, containingClass)); } catch (IllegalAccessException | InstantiationException e) { throw new GraphQLAnnotationsException(e); } return builder.build(); }
@BeforeMethod public void setUp() throws NoSuchFieldException { directiveArgumentCreator = Mockito.mock(DirectiveArgumentCreator.class); commonPropertiesCreator = Mockito.mock(CommonPropertiesCreator.class); when(directiveArgumentCreator.getArgument(UpperDirective.class.getDeclaredField("isActive"), UpperDirective.class)) .thenReturn(GraphQLArgument.newArgument().name("isActive").type(GraphQLBoolean).defaultValue(true).build()); when(commonPropertiesCreator.getDescription(any())).thenCallRealMethod(); when(commonPropertiesCreator.getName(any())).thenCallRealMethod(); directiveCreator = new DirectiveCreator(directiveArgumentCreator, commonPropertiesCreator); }
/** * Return a new webroot path argument. * * @return */ public GraphQLArgument createPathArg() { return newArgument().name("path").type(GraphQLString).description("Webroot path which points to a container of a node.").build(); }
/** * Return a new argument for the uuid. * * @param description * @return */ public GraphQLArgument createUuidArg(String description) { return newArgument().name("uuid").type(GraphQLString).description(description).build(); }
private GraphQLArgument stringTemplate(String name, String defaultValue) { GraphQLArgument.Builder argument = GraphQLArgument.newArgument().name(name).type( Scalars.GraphQLString); if (defaultValue != null) { argument.defaultValue(defaultValue); } return argument.build(); }
/** * Same effect as the argument(GraphQLArgument). Builder.build() is called * from within * * @param builder an un-built/incomplete GraphQLArgument * * @return this */ public Builder argument(GraphQLArgument.Builder builder) { argument(builder.build()); return this; }
private GraphQLArgument toGraphQLArgument(DirectiveArgument directiveArgument, BuildContext buildContext) { GraphQLArgument argument = newArgument() .name(directiveArgument.getName()) .description(directiveArgument.getDescription()) .type(toGraphQLInputType(directiveArgument.getJavaType(), buildContext)) .value(directiveArgument.getValue()) .defaultValue(directiveArgument.getDefaultValue()) .withDirectives(toGraphQLDirectives(directiveArgument.getTypedElement(), buildContext.directiveBuilder::buildArgumentDefinitionDirectives, buildContext)) .build(); return buildContext.transformers.transform(argument, directiveArgument, this, buildContext); }
.name("date") .type(Scalars.GraphQLString) .build()) .dataFetcher(environment -> { try { // TODO: Add our own scalar types for at least serviceDate and FeedId .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()) .dataFetcher(environment -> index.stopTimesForStop((Stop) environment.getSource(), .build()) .argument(GraphQLArgument.newArgument() .name("timeRange") .type(Scalars.GraphQLInt)
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; }
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(); }
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); }
private List<GraphQLArgument> transferMissingArguments(List<GraphQLArgument> arguments, GraphQLDirective directiveDefinition) { Map<String, GraphQLArgument> declaredArgs = FpKit.getByName(arguments, GraphQLArgument::getName, FpKit.mergeFirst()); List<GraphQLArgument> argumentsOut = new ArrayList<>(arguments); for (GraphQLArgument directiveDefArg : directiveDefinition.getArguments()) { if (!declaredArgs.containsKey(directiveDefArg.getName())) { GraphQLArgument missingArg = GraphQLArgument.newArgument() .name(directiveDefArg.getName()) .description(directiveDefArg.getDescription()) .definition(directiveDefArg.getDefinition()) .type(directiveDefArg.getType()) .defaultValue(directiveDefArg.getDefaultValue()) .value(directiveDefArg.getDefaultValue()) .build(); argumentsOut.add(missingArg); } } return argumentsOut; }
private GraphQLArgument buildDirectiveArgumentFromDefinition(InputValueDefinition arg, Function<Type, GraphQLInputType> inputTypeFactory) { GraphQLArgument.Builder builder = GraphQLArgument.newArgument() .name(arg.getName()) .definition(arg); GraphQLInputType inputType = inputTypeFactory.apply(arg.getType()); builder.type(inputType); builder.value(buildValue(arg.getDefaultValue(), inputType)); builder.defaultValue(buildValue(arg.getDefaultValue(), inputType)); return builder.build(); }
/** * Same effect as the argument(GraphQLArgument). Builder.build() is called * from within * * @param builder an un-built/incomplete GraphQLArgument * * @return this */ public Builder argument(GraphQLArgument.Builder builder) { argument(builder.build()); return this; }
/** * Same effect as the argument(GraphQLArgument). Builder.build() is called * from within * * @param builder an un-built/incomplete GraphQLArgument * * @return this */ public Builder argument(GraphQLArgument.Builder builder) { return argument(builder.build()); }