io.smallrye.graphql.client.core.Fragment Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of smallrye-graphql-client-api Show documentation
Show all versions of smallrye-graphql-client-api Show documentation
SmallRye specific Client API, extending the MicroProfile client api, allowing us to play with the api first before we move it to the spec
package io.smallrye.graphql.client.core;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.validation.NameValidation.validateFragmentName;
import static io.smallrye.graphql.client.core.utils.validation.NameValidation.validateName;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import java.util.List;
/**
* Represents a named fragment definition in a GraphQL document. Such definition consists of a name,
* target type, and a set of fields.
*/
public interface Fragment extends FragmentOrOperation {
/*
* Static factory methods
*/
static List fragments(Fragment... fragments) {
return asList(fragments);
}
static FragmentBuilder fragment(String name) {
return new FragmentBuilder(name);
}
/*
* Getter/Setter
*/
String getName();
void setName(String name);
String getTargetType();
void setTargetType(String name);
List getFields();
void setFields(List fields);
List getDirectives();
void setDirectives(List directives);
class FragmentBuilder {
private String name;
private String targetType;
private List directives;
private List fields;
FragmentBuilder(String name) {
this.name = validateFragmentName(name);
}
public Fragment on(String targetType, FieldOrFragment... fields) {
this.targetType = validateName(targetType);
this.directives = emptyList();
this.fields = asList(fields);
return build();
}
public Fragment on(String targetType, List directives, FieldOrFragment... fields) {
this.targetType = validateName(targetType);
this.directives = directives;
this.fields = asList(fields);
return build();
}
Fragment build() {
Fragment fragment = getNewInstanceOf(Fragment.class);
fragment.setName(name);
fragment.setTargetType(targetType);
fragment.setDirectives(directives);
fragment.setFields(fields);
return fragment;
}
}
}