String argsString(List<GraphQLArgument> arguments) { boolean hasDescriptions = arguments.stream().anyMatch(arg -> !isNullOrEmpty(arg.getDescription())); String halfPrefix = hasDescriptions ? " " : ""; String prefix = hasDescriptions ? " " : ""; sb.append("\n"); String description = argument.getDescription(); if (!isNullOrEmpty(description)) { String[] descriptionSplitByNewlines = description.split("\n");
public Builder(GraphQLArgument existing) { this.name = existing.getName(); this.type = existing.getType(); this.value = existing.getValue(); this.defaultValue = existing.getDefaultValue(); this.description = existing.getDescription(); this.definition = existing.getDefinition(); this.directives.putAll(FpKit.getByName(existing.getDirectives(), GraphQLDirective::getName)); }
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; }
String argsString(Class<? extends GraphQLType> parent, List<GraphQLArgument> arguments) { boolean hasDescriptions = arguments.stream().anyMatch(arg -> !isNullOrEmpty(arg.getDescription())); String halfPrefix = hasDescriptions ? " " : ""; String prefix = hasDescriptions ? " " : ""; sb.append("\n"); String description = argument.getDescription(); if (!isNullOrEmpty(description)) { String[] descriptionSplitByNewlines = description.split("\n");
private GraphQLFieldDefinition buildRelayMutation(Method method, ProcessingElementsContainer container, GraphQLFieldDefinition.Builder builder, GraphQLOutputType outputType, List<GraphQLArgument> args) { GraphQLFieldDefinition relayFieldDefinition; if (!(outputType instanceof GraphQLObjectType || outputType instanceof GraphQLInterfaceType)) { throw new RuntimeException("outputType should be an object or an interface"); } StringBuilder titleBuffer = new StringBuilder(method.getName()); titleBuffer.setCharAt(0, Character.toUpperCase(titleBuffer.charAt(0))); String title = titleBuffer.toString(); List<GraphQLFieldDefinition> fieldDefinitions = outputType instanceof GraphQLObjectType ? ((GraphQLObjectType) outputType).getFieldDefinitions() : ((GraphQLInterfaceType) outputType).getFieldDefinitions(); relayFieldDefinition = container.getRelay().mutationWithClientMutationId(title, method.getName(), args.stream(). map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). collect(Collectors.toList()), fieldDefinitions, new StaticDataFetcher(null)); builder.argument(relayFieldDefinition.getArguments()).type(relayFieldDefinition.getType()); return relayFieldDefinition; }
public Builder(GraphQLArgument existing) { this.name = existing.getName(); this.type = existing.getType(); this.value = existing.getValue(); this.defaultValue = existing.getDefaultValue(); this.description = existing.getDescription(); this.definition = existing.getDefinition(); this.directives.putAll(FpKit.getByName(existing.getDirectives(), GraphQLDirective::getName)); }
relay = RELAY_TYPES.mutationWithClientMutationId(title, method.getName(), args.stream(). map(t -> newInputObjectField().name(t.getName()).type(t.getType()).description(t.getDescription()).build()). collect(Collectors.toList()), fieldDefinitions, null); builder.argument(relay.getArguments());
assertEquals(args.get(1).getName(), "b"); assertEquals(args.get(1).getType(), GraphQLString); assertEquals(args.get(1).getDescription(), "b");
@Test public void getArgument_goodFieldSupplied_correctArgumentCreated() throws NoSuchFieldException { GraphQLArgument isActive = directiveArgumentCreator.getArgument(this.getClass().getDeclaredField("isActive"), DirectiveArgumentCreatorTest.class); // Assert assertEquals(isActive.getName(), "isActive"); assertEquals(isActive.getDefaultValue(), true); assertEquals(isActive.getDescription(), "isActive"); assertEquals(isActive.getType(), GraphQLBoolean); } }
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; }
public static GraphQLArgument.Builder notNull (GraphQLArgument.Builder aBuilder) { GraphQLArgument arg = aBuilder.build(); return GraphQLArgument.newArgument() .name(arg.getName()) .defaultValue(arg.getDefaultValue()) .definition(arg.getDefinition()) .description(arg.getDescription()) .type(new GraphQLNonNull(arg.getType())); }
.map(arg -> GraphQLInputObjectField.newInputObjectField() .name(arg.getName()) .description(arg.getDescription()) .type(arg.getType()) .defaultValue(arg.getDefaultValue())
private static GraphQLArgument getArgument(final graphql.schema.GraphQLArgument argument){ final GraphQLArgument graphQLArgument = new GraphQLArgument(); final graphql.schema.GraphQLType type = argument.getType(); final boolean nullable = isNullable(type); final boolean listable = isListable(type); final graphql.schema.GraphQLType coreType = getType(argument.getType()); final GraphQLAttributeType attributeType = getAttributeType(coreType); final String id = generateId(); graphQLArgument.setName(argument.getName()); graphQLArgument.setId(id); graphQLArgument.setNullable(nullable); graphQLArgument.setDescription(argument.getDescription()); graphQLArgument.setListable(listable); graphQLArgument.setAttributeType(attributeType); graphQLArgument.setDefaultValue(argument.getDefaultValue()); if(GraphQLAttributeType.OBJECT_TYPE.equals(attributeType)){ graphQLArgument.setTypeName(coreType.getName()); } else if(GraphQLAttributeType.ENUM.equals(attributeType)){ graphQLArgument.setTypeName(coreType.getName()); } return graphQLArgument; }
@Test public void test_directive_creation() { // Act GraphQLDirective directive = GraphQLAnnotations.directive(UpperDirective.class); // Assert assertEquals(directive.getName(), "upper"); assertEquals(directive.getDescription(), "makes string upper case"); assertArrayEquals(directive.validLocations().toArray(), new Introspection.DirectiveLocation[]{Introspection.DirectiveLocation.FIELD_DEFINITION, Introspection.DirectiveLocation.INTERFACE}); GraphQLArgument isActive = directive.getArgument("isActive"); assertNotNull(isActive); assertEquals(isActive.getName(), "isActive"); assertEquals(isActive.getType(), GraphQLBoolean); assertEquals(isActive.getDefaultValue(), true); GraphQLArgument suffixToAdd = directive.getArgument("suffixToAdd"); assertNotNull(suffixToAdd); assertEquals(suffixToAdd.getType(), GraphQLString); assertEquals(suffixToAdd.getDescription(), "adds suffix to the string"); assertEquals(suffixToAdd.getDefaultValue(), ""); GraphQLArgument noDefaultValue = directive.getArgument("noDefaultValue"); assertNotNull(noDefaultValue); assertNull(noDefaultValue.getDefaultValue()); } }