io.leangen.graphql.annotations.GraphQLArgument Java Examples

The following examples show how to use io.leangen.graphql.annotations.GraphQLArgument. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserService.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
@GraphQLQuery(name = "users")
public List<User<String>> getUsersById(@GraphQLArgument(name = "id") @GraphQLId Integer id) {
    User<String> user = new User<>();
    user.id = id;
    user.name = "Tatko";
    user.uuid = UUID.randomUUID();
    user.registrationDate = new Date();
    user.addresses = addresses;
    User<String> user2 = new User<>();
    user2.id = id + 1;
    user2.name = "Tzar";
    user2.uuid = UUID.randomUUID();
    user2.registrationDate = new Date();
    user2.addresses = addresses;
    return Arrays.asList(user, user2);
}
 
Example #2
Source File: AnnotatedArgumentBuilder.java    From graphql-spqr with Apache License 2.0 6 votes vote down vote up
protected String getArgumentName(Parameter parameter, AnnotatedType parameterType, ArgumentBuilderParams builderParams) {
    if (Optional.ofNullable(parameterType.getAnnotation(GraphQLId.class)).filter(GraphQLId::relayId).isPresent()) {
        return GraphQLId.RELAY_ID_FIELD_NAME;
    }
    GraphQLArgument meta = parameter.getAnnotation(GraphQLArgument.class);
    if (meta != null && !meta.name().isEmpty()) {
        return builderParams.getEnvironment().messageBundle.interpolate(meta.name());
    } else {
        if (!parameter.isNamePresent() && builderParams.getInclusionStrategy().includeArgumentForMapping(parameter, parameterType, builderParams.getDeclaringType())) {
            log.warn("No explicit argument name given and the parameter name lost in compilation: "
                    + parameter.getDeclaringExecutable().toGenericString() + "#" + parameter.toString()
                    + ". For details and possible solutions see " + Urls.Errors.MISSING_ARGUMENT_NAME);
        }
        return parameter.getName();
    }
}
 
Example #3
Source File: BatchingTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Batched
@GraphQLQuery
public List<Education> educations(@GraphQLArgument(name = "users") @GraphQLContext List<SimpleUser> users, @GraphQLRootContext AtomicBoolean flag) {
    assertEquals(3, users.size());
    flag.getAndSet(true);
    return users.stream()
            .map(u -> u.getEducation(2000 + u.getFullName().charAt(0)))
            .collect(Collectors.toList());
}
 
Example #4
Source File: ToDoService.java    From micronaut-graphql with Apache License 2.0 5 votes vote down vote up
@GraphQLMutation
public boolean deleteToDo(@GraphQLNonNull @GraphQLArgument(name = "id") String id) {
    ToDo toDo = toDoRepository.findById(id);
    if (toDo != null) {
        toDoRepository.deleteById(id);
        return true;
    } else {
        return false;
    }
}
 
Example #5
Source File: AnnotatedArgumentBuilder.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
protected Object defaultValue(Parameter parameter, AnnotatedType parameterType, GlobalEnvironment environment) {

        GraphQLArgument meta = parameter.getAnnotation(GraphQLArgument.class);
        if (meta == null) return null;
        try {
            return defaultValueProvider(meta.defaultValueProvider(), environment)
                    .getDefaultValue(parameter, environment.getMappableInputType(parameterType), ReservedStrings.decode(environment.messageBundle.interpolate(meta.defaultValue())));
        } catch (ReflectiveOperationException e) {
            throw new IllegalArgumentException(
                    meta.defaultValueProvider().getName() + " must expose a public default constructor, or a constructor accepting " + GlobalEnvironment.class.getName(), e);
        }
    }
 
Example #6
Source File: RelayTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@GraphQLQuery(name = "extended")
public ExtendedPage<Book> getExtended(@GraphQLArgument(name = "first") int first, @GraphQLArgument(name = "after") String after) {
    List<Book> books = new ArrayList<>();
    books.add(new Book("Tesseract", "x123"));
    long count = 100L;
    long offset = Long.parseLong(after);
    return PageFactory.createOffsetBasedPage(books, count, offset, (edges, info) -> new ExtendedPage<>(edges, info, count));
}
 
Example #7
Source File: TypeResolverTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@GraphQLQuery(name = "repo")
public List<Stream<GenericRepo>> getRepo(@GraphQLArgument(name = "id") int id) {
    if (id % 2 == 0) {
        return Collections.singletonList(Stream.of(new SessionRepo<>(new Street("Baker street", 1))));
    } else {
        return Collections.singletonList(Stream.of(new SessionRepo<>(new Education("Alma Mater", 1600, 1604))));
    }
}
 
Example #8
Source File: ToDoService.java    From micronaut-graphql with Apache License 2.0 5 votes vote down vote up
@GraphQLMutation
public boolean completeToDo(@GraphQLNonNull @GraphQLArgument(name = "id") String id) {
    ToDo toDo = toDoRepository.findById(id);
    if (toDo != null) {
        toDo.setCompleted(true);
        toDoRepository.save(toDo);
        return true;
    } else {
        return false;
    }
}
 
Example #9
Source File: RelayTest.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@GraphQLQuery(name = "extended")
public ExtendedConnection<ExtendedEdge<Book>> getExtended(@GraphQLArgument(name = "first") int first, @GraphQLArgument(name = "after") String after) {
    List<Book> books = new ArrayList<>();
    books.add(new Book("Tesseract", "x123"));
    long count = 100L;
    long offset = Long.parseLong(after);
    Iterator<ExtendedEdge.COLOR> colors = Arrays.asList(ExtendedEdge.COLOR.WHITE, ExtendedEdge.COLOR.BLACK).iterator();
    return PageFactory.createOffsetBasedConnection(books, count, offset,
            (node, cursor) -> new ExtendedEdge<>(node, cursor, colors.next()), (edges, info) -> new ExtendedConnection<>(edges, info, count));
}
 
Example #10
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "usersArr")
@SuppressWarnings("unchecked")
public User<String>[] getUsersByAnyEducationArray(@GraphQLArgument(name = "educations") T[] educations) {
    List<User<String>> users = getUsersById(1);
    return users.toArray(new User[0]);
}
 
Example #11
Source File: ToDoService.java    From micronaut-graphql with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation
public ToDo createToDo(@GraphQLNonNull @GraphQLArgument(name = "title") String title) {
    ToDo toDo = new ToDo(title);
    return toDoRepository.save(toDo);
}
 
Example #12
Source File: ConversionTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery
public AnnotatedId other(@GraphQLArgument(name = "id") AnnotatedId id) {
    return id;
}
 
Example #13
Source File: PolymorphicJsonTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery
public Parent<String> test(@GraphQLArgument(name = "container") Parent<String> container) {
    return container;
}
 
Example #14
Source File: ComplexityTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "pets")
public Page<Pet> findPets(@GraphQLArgument(name = "first") int first, @GraphQLArgument(name = "after") String after) {
    return PageFactory.createPage(Collections.emptyList(), PageFactory.offsetBasedCursorProvider(0L), false, false);
}
 
Example #15
Source File: ComplexityTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation
@GraphQLComplexity("2 + childScore")
public @GraphQLNonNull List<@GraphQLNonNull Pet> addPet(@GraphQLArgument(name = "pet") Pet pet) {
    return Collections.singletonList(pet);
}
 
Example #16
Source File: ArgumentInjectionTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = ECHO)
public @GraphQLScalar Street echoArgument(@GraphQLArgument(name = "user") @GraphQLScalar Street street) {
    return street;
}
 
Example #17
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation(name = "upMe")
public Map<String, String> getUpdateCurrentUser(@GraphQLArgument(name = "updates") Map<String, String> updates) {
    return updates;
}
 
Example #18
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "users")
public List<User<String>> getUserByUuid(@GraphQLArgument(name = "uuid") UUID uuid) {
    return getUsersById(1);
}
 
Example #19
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation(name = "updateUsername")
public User<String> updateUsername(@GraphQLContext User<String> user, @GraphQLArgument(name = "username") String username) {
    user.name = username;
    return user;
}
 
Example #20
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "usersByDate")
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public List<User<String>> getUsersByDate(@GraphQLArgument(name = "regDate") Optional<Date> date) {
    return getUsersById(1);
}
 
Example #21
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "users")
@GraphQLComplexity("2 * childScore")
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public List<User<String>> getUsersByRegDate(@GraphQLArgument(name = "regDate") Optional<Date> date) {
    return getUsersById(1);
}
 
Example #22
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "users")
public List<User<String>> getUsersByAnyEducation(@GraphQLArgument(name = "educations") List<? super T> educations) {
    return getUsersById(1);
}
 
Example #23
Source File: UserService.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "users")
public List<User<String>> getUsersByEducation(@GraphQLArgument(name = "education") Education education) {
    return getUsersById(1);
}
 
Example #24
Source File: GenericItemRepo.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation
public void addItems(@GraphQLArgument(name = "items") Set<T> items) {
    items.forEach(item -> itemsByName.putIfAbsent(item.toString(), item));
}
 
Example #25
Source File: GenericItemRepo.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLMutation
public void addItem(@GraphQLArgument(name = "name") String name, @GraphQLArgument(name = "item") T item) {
    itemsByName.putIfAbsent(name, item);
}
 
Example #26
Source File: GenericItemRepo.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery
public T contains(@GraphQLArgument(name = "item") T item) {
    return itemsByName.containsValue(item) ? item : null;
}
 
Example #27
Source File: ResolverBuilder_TestConfig.java    From graphql-spqr-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "springPageComponent_users")
public Page<User> users(@GraphQLArgument(name = "first") int first, @GraphQLArgument(name = "after") String after) {
    return new PageImpl<>(users.subList(0, first), PageRequest.of(0, first), users.size());
}
 
Example #28
Source File: ImplementationAutoDiscoveryTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "find")
public Auto findDeep(@GraphQLArgument(name = "one") boolean one) {
    return one ? new One() : new Two();
}
 
Example #29
Source File: ImplementationAutoDiscoveryTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "find")
public Manual findFlat(@GraphQLArgument(name = "one") boolean one) {
    return one ? new One() : new Two();
}
 
Example #30
Source File: NestedQueryTest.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@GraphQLQuery(name = "books")
public RelayTest.Book[] getBooks(@GraphQLArgument(name = "after") LocalDate after) {
    return new RelayTest.Book[] {new RelayTest.Book("Tesseract", "x123")};
}