Skip to content

Commit

Permalink
added optimalization for dynamic client via service loading of Factor…
Browse files Browse the repository at this point in the history
…y Classes
  • Loading branch information
mskacelik committed Oct 2, 2024
1 parent 1f30a07 commit e2c49f1
Show file tree
Hide file tree
Showing 71 changed files with 423 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.ArgumentFactory;

public interface Argument extends Buildable {
/*
* Static factory methods
Expand All @@ -15,7 +17,7 @@ static List<Argument> args(Argument... args) {

// (name, raw value)
static Argument arg(String name, Object value) {
Argument argument = getNewInstanceOf(Argument.class);
Argument argument = getNewInstanceFromFactory(ArgumentFactory.class);

argument.setName(name);
argument.setValue(value);
Expand All @@ -25,7 +27,7 @@ static Argument arg(String name, Object value) {

// (name, inputObject)
static Argument arg(String name, InputObject inputObject) {
Argument argument = getNewInstanceOf(Argument.class);
Argument argument = getNewInstanceFromFactory(ArgumentFactory.class);

argument.setName(name);
argument.setValue(inputObject);
Expand All @@ -35,7 +37,7 @@ static Argument arg(String name, InputObject inputObject) {

// (name, variable)
static Argument arg(String name, Variable var) {
Argument argument = getNewInstanceOf(Argument.class);
Argument argument = getNewInstanceFromFactory(ArgumentFactory.class);

argument.setName(name);
argument.setValue(var);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.DirectiveFactory;

public interface Directive extends Buildable {
static List<Directive> directives(Directive... directives) {
return asList(directives);
}

static Directive directive(String name) {
Directive directive = getNewInstanceOf(Directive.class);
Directive directive = getNewInstanceFromFactory(DirectiveFactory.class);

directive.setName(name);
directive.setDirectiveArguments(emptyList());
Expand All @@ -21,7 +23,7 @@ static Directive directive(String name) {
}

static Directive directive(String name, DirectiveArgument... directiveArguments) {
Directive directive = getNewInstanceOf(Directive.class);
Directive directive = getNewInstanceFromFactory(DirectiveFactory.class);

directive.setName(name);
directive.setDirectiveArguments(asList(directiveArguments));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.DirectiveArgumentFactory;

public interface DirectiveArgument extends Buildable {
static List<DirectiveArgument> directiveArgs(DirectiveArgument... directiveArgs) {
return asList(directiveArgs);
}

static DirectiveArgument directiveArg(String name, Object value) {
DirectiveArgument directiveArgument = getNewInstanceOf(DirectiveArgument.class);
DirectiveArgument directiveArgument = getNewInstanceFromFactory(DirectiveArgumentFactory.class);

directiveArgument.setName(name);
directiveArgument.setValue(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.DocumentFactory;

public interface Document extends Buildable {

/*
* Static factory methods
*/
static Document document(FragmentOrOperation... operations) {
Document document = getNewInstanceOf(Document.class);
Document document = getNewInstanceFromFactory(DocumentFactory.class);

document.setOperations(asList(operations));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;

import io.smallrye.graphql.client.core.factory.EnumFactory;

public interface Enum extends Buildable {
/*
* Static factory methods
*/
static Enum gqlEnum(String value) {
Enum gqlEnum = getNewInstanceOf(Enum.class);
Enum gqlEnum = getNewInstanceFromFactory(EnumFactory.class);

gqlEnum.setValue(value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.FieldFactory;

public interface Field extends FieldOrFragment {
/*
* Static factory methods
Expand All @@ -16,7 +18,7 @@ static List<FieldOrFragment> fields(FieldOrFragment... fields) {

// (name)
static Field field(String name) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(emptyList());
Expand All @@ -28,7 +30,7 @@ static Field field(String name) {

// (name, subfields)
static Field field(String name, FieldOrFragment... fields) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(emptyList());
Expand All @@ -40,7 +42,7 @@ static Field field(String name, FieldOrFragment... fields) {

// (name, args)
static Field field(String name, Argument... args) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(asList(args));
Expand All @@ -52,7 +54,7 @@ static Field field(String name, Argument... args) {

// (name, directives)
static Field fieldWithDirectives(String name, Directive... directives) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(emptyList());
Expand All @@ -64,7 +66,7 @@ static Field fieldWithDirectives(String name, Directive... directives) {

// (name, args, subfields)
static Field field(String name, List<Argument> args, FieldOrFragment... fields) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(args);
Expand All @@ -76,7 +78,7 @@ static Field field(String name, List<Argument> args, FieldOrFragment... fields)

// (name, args, directives)
static Field fieldWithDirectives(String name, List<Argument> args, List<Directive> directives) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(args);
Expand All @@ -88,7 +90,7 @@ static Field fieldWithDirectives(String name, List<Argument> args, List<Directiv

// (name, directives, fields)
static Field fieldWithDirectives(String name, List<Directive> directives, FieldOrFragment... fields) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(emptyList());
Expand All @@ -100,7 +102,7 @@ static Field fieldWithDirectives(String name, List<Directive> directives, FieldO

// (name, args, directives, subfields)
static Field fieldWithDirectives(String name, List<Argument> args, List<Directive> directives, FieldOrFragment... fields) {
Field field = getNewInstanceOf(Field.class);
Field field = getNewInstanceFromFactory(FieldFactory.class);

field.setName(name);
field.setArguments(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
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;

import io.smallrye.graphql.client.core.factory.FragmentFactory;

/**
* Represents a named fragment definition in a GraphQL document. Such definition consists of a name,
* target type, and a set of fields.
Expand Down Expand Up @@ -72,7 +74,7 @@ public Fragment on(String targetType, List<Directive> directives, FieldOrFragmen
}

Fragment build() {
Fragment fragment = getNewInstanceOf(Fragment.class);
Fragment fragment = getNewInstanceFromFactory(FragmentFactory.class);
fragment.setName(name);
fragment.setTargetType(targetType);
fragment.setDirectives(directives);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.FragmentReferenceFactory;

/**
* Represents a reference to a named fragment.
*/
Expand All @@ -16,7 +18,7 @@ public interface FragmentReference extends FieldOrFragment {
* In the resulting document, this will appear as `...FRAGMENTNAME`
*/
static FragmentReference fragmentRef(String name) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
FragmentReference ref = getNewInstanceFromFactory(FragmentReferenceFactory.class);
ref.setName(name);
ref.setDirectives(emptyList());
return ref;
Expand All @@ -28,7 +30,7 @@ static FragmentReference fragmentRef(String name) {
* this will appear as `...FRAGMENTNAME`
*/
static FragmentReference fragmentRef(Fragment fragment) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
FragmentReference ref = getNewInstanceFromFactory(FragmentReferenceFactory.class);
ref.setName(fragment.getName());
ref.setDirectives(emptyList());
return ref;
Expand All @@ -39,7 +41,7 @@ static FragmentReference fragmentRef(Fragment fragment) {
* In the resulting document, this will appear as `...FRAGMENTNAME @DIRECTIVE`
*/
static FragmentReference fragmentRefWithDirective(String name, Directive... directives) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
FragmentReference ref = getNewInstanceFromFactory(FragmentReferenceFactory.class);
ref.setName(name);
ref.setDirectives(asList(directives));
return ref;
Expand All @@ -51,7 +53,7 @@ static FragmentReference fragmentRefWithDirective(String name, Directive... dire
* this will appear as `...FRAGMENTNAME @DIRECTIVE`
*/
static FragmentReference fragmentRefWithDirective(Fragment fragment, Directive... directives) {
FragmentReference ref = getNewInstanceOf(FragmentReference.class);
FragmentReference ref = getNewInstanceFromFactory(FragmentReferenceFactory.class);
ref.setName(fragment.getName());
ref.setDirectives(asList(directives));
return ref;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.InlineFragmentFactory;

/**
* Represents an inline fragment in a GraphQL document. This can be used
* anywhere where a field is expected (thus it implements `FieldOrFragment`).
*/
public interface InlineFragment extends FieldOrFragment {

static InlineFragment on(String type, FieldOrFragment... fields) {
InlineFragment fragment = getNewInstanceOf(InlineFragment.class);
InlineFragment fragment = getNewInstanceFromFactory(InlineFragmentFactory.class);

fragment.setType(type);
fragment.setDirectives(emptyList());
Expand All @@ -23,7 +25,7 @@ static InlineFragment on(String type, FieldOrFragment... fields) {
}

static InlineFragment on(String type, List<Directive> directives, FieldOrFragment... fields) {
InlineFragment fragment = getNewInstanceOf(InlineFragment.class);
InlineFragment fragment = getNewInstanceFromFactory(InlineFragmentFactory.class);

fragment.setType(type);
fragment.setDirectives(directives);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;
import static java.util.Arrays.asList;

import java.util.List;

import io.smallrye.graphql.client.core.factory.InputObjectFactory;

public interface InputObject extends Buildable {
/*
* Static factory methods
*/
static InputObject inputObject(InputObjectField... inputObjectFields) {
InputObject inputObject = getNewInstanceOf(InputObject.class);
InputObject inputObject = getNewInstanceFromFactory(InputObjectFactory.class);

inputObject.setInputObjectFields(asList(inputObjectFields));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.smallrye.graphql.client.core;

import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceOf;
import static io.smallrye.graphql.client.core.utils.ServiceUtils.getNewInstanceFromFactory;

import io.smallrye.graphql.client.core.factory.InputObjectFieldFactory;

public interface InputObjectField extends Buildable {

Expand All @@ -9,7 +11,7 @@ public interface InputObjectField extends Buildable {
*/
// (name, value)
static InputObjectField prop(String name, Object value) {
InputObjectField inputObjectField = getNewInstanceOf(InputObjectField.class);
InputObjectField inputObjectField = getNewInstanceFromFactory(InputObjectFieldFactory.class);

inputObjectField.setName(name);
inputObjectField.setValue(value);
Expand All @@ -19,7 +21,7 @@ static InputObjectField prop(String name, Object value) {

// (name, variable)
static InputObjectField prop(String name, Variable var) {
InputObjectField inputObjectField = getNewInstanceOf(InputObjectField.class);
InputObjectField inputObjectField = getNewInstanceFromFactory(InputObjectFieldFactory.class);

inputObjectField.setName(name);
inputObjectField.setValue(var);
Expand Down
Loading

0 comments on commit e2c49f1

Please sign in to comment.