Skip to content

Commit 79c1335

Browse files
Merge pull request #49 from phocassoftware/format
format
2 parents d89ab6b + 57ff837 commit 79c1335

File tree

80 files changed

+1633
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1633
-1195
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
with:
1919
java-version: 21
2020
distribution: zulu
21+
- name: Formatter Check
22+
run: mvn formatter:validate
2123
- name: Build with Maven
2224
run: mvn -B test --file pom.xml
2325
- uses: ashley-taylor/junit-report-annotations-action@master

formatter.xml

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/AuthorizerSchema.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public DataFetcher<?> wrap(DataFetcher<?> fetcher, Method method) {
186186
throw GraphqlErrorException.newErrorException().message("unauthorized").errorClassification(ErrorType.UNAUTHORIZED).build();
187187
}
188188
} else {
189-
//only other type that passes checks above
189+
// only other type that passes checks above
190190
CompletableFuture<Boolean> allowed = (CompletableFuture<Boolean>) allow;
191191

192192
return allowed

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/DirectiveProcessor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ public static DirectiveProcessor build(EntityProcessor entityProcessor, Class<?
5252
builder.argument(argument);
5353

5454
// Add a builder to the builders list (in order to populate applied directives)
55-
builders.put(
56-
name,
57-
object -> {
58-
try {
59-
return GraphQLAppliedDirectiveArgument.newArgument().name(name).type(argumentType).valueProgrammatic(method.invoke(object)).build();
60-
} catch (IllegalAccessException | InvocationTargetException e) {
61-
throw new RuntimeException(e);
55+
builders
56+
.put(
57+
name,
58+
object -> {
59+
try {
60+
return GraphQLAppliedDirectiveArgument.newArgument().name(name).type(argumentType).valueProgrammatic(method.invoke(object)).build();
61+
} catch (IllegalAccessException | InvocationTargetException e) {
62+
throw new RuntimeException(e);
63+
}
6264
}
63-
}
64-
);
65+
);
6566
}
6667
return new DirectiveProcessor(builder.build(), builders);
6768
}

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/DirectivesSchema.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private DirectivesSchema(
4747
this.directives = directives;
4848
}
4949

50-
//TODO:mess of exceptions
50+
// TODO:mess of exceptions
5151
public static DirectivesSchema build(List<RestrictTypeFactory<?>> globalDirectives, Set<Class<?>> directiveTypes) throws ReflectiveOperationException {
5252
Map<Class<? extends Annotation>, DirectiveCaller<?>> targets = new HashMap<>();
5353

@@ -89,31 +89,30 @@ public Stream<GraphQLDirective> getSchemaDirective() {
8989
}
9090

9191
private DataFetcher<?> wrap(RestrictTypeFactory<?> directive, DataFetcher<?> fetcher) {
92-
//TODO: hate having this cache here would love to scope against the env object but nothing to hook into dataload caused global leak
92+
// TODO: hate having this cache here would love to scope against the env object but nothing to hook into dataload caused global leak
9393
Map<DataFetchingEnvironment, CompletableFuture<RestrictType>> cache = Collections.synchronizedMap(new WeakHashMap<>());
9494

95-
return env ->
96-
cache
97-
.computeIfAbsent(env, key -> directive.create(key).thenApply(t -> t))
98-
.thenCompose(restrict -> {
99-
try {
100-
Object response = fetcher.get(env);
101-
if (response instanceof CompletionStage) {
102-
return ((CompletionStage) response).thenCompose(r -> applyRestrict(restrict, r));
103-
}
104-
return applyRestrict(restrict, response);
105-
} catch (Exception e) {
106-
if (e instanceof RuntimeException) {
107-
throw (RuntimeException) e;
108-
}
109-
throw new RuntimeException(e);
95+
return env -> cache
96+
.computeIfAbsent(env, key -> directive.create(key).thenApply(t -> t))
97+
.thenCompose(restrict -> {
98+
try {
99+
Object response = fetcher.get(env);
100+
if (response instanceof CompletionStage) {
101+
return ((CompletionStage) response).thenCompose(r -> applyRestrict(restrict, r));
110102
}
111-
});
103+
return applyRestrict(restrict, response);
104+
} catch (Exception e) {
105+
if (e instanceof RuntimeException) {
106+
throw (RuntimeException) e;
107+
}
108+
throw new RuntimeException(e);
109+
}
110+
});
112111
}
113112

114113
public boolean target(Method method, TypeMeta meta) {
115114
for (var global : this.global) {
116-
//TODO: extract class
115+
// TODO: extract class
117116
if (global.extractType().isAssignableFrom(meta.getType())) {
118117
return true;
119118
}
@@ -181,8 +180,8 @@ private <T> CompletableFuture<Object> applyRestrict(RestrictType restrict, Objec
181180
private static <T> CompletableFuture<List<T>> all(List<CompletableFuture<T>> toReturn) {
182181
return CompletableFuture
183182
.allOf(toReturn.toArray(CompletableFuture[]::new))
184-
.thenApply(__ ->
185-
toReturn
183+
.thenApply(
184+
__ -> toReturn
186185
.stream()
187186
.map(m -> {
188187
try {

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/EntityProcessor.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,29 @@ public EntityHolder getEntity(Class<?> type) {
103103

104104
EntityHolder getEntity(TypeMeta meta) {
105105
String name = EntityUtil.getName(meta);
106-
return entities.computeIfAbsent(
107-
name,
108-
__ -> {
109-
Class<?> type = meta.getType();
110-
Type genericType = meta.getGenericType();
111-
if (genericType == null) {
112-
genericType = type;
113-
}
114-
try {
115-
if (type.isAnnotationPresent(Scalar.class)) {
116-
return new ScalarEntity(directives, meta);
106+
return entities
107+
.computeIfAbsent(
108+
name,
109+
__ -> {
110+
Class<?> type = meta.getType();
111+
Type genericType = meta.getGenericType();
112+
if (genericType == null) {
113+
genericType = type;
117114
}
118-
if (type.isEnum()) {
119-
return new EnumEntity(directives, meta);
120-
} else {
121-
return new ObjectEntity(this, meta);
115+
try {
116+
if (type.isAnnotationPresent(Scalar.class)) {
117+
return new ScalarEntity(directives, meta);
118+
}
119+
if (type.isEnum()) {
120+
return new EnumEntity(directives, meta);
121+
} else {
122+
return new ObjectEntity(this, meta);
123+
}
124+
} catch (ReflectiveOperationException | RuntimeException e) {
125+
throw new RuntimeException("Failed to build schema for class " + type, e);
122126
}
123-
} catch (ReflectiveOperationException | RuntimeException e) {
124-
throw new RuntimeException("Failed to build schema for class " + type, e);
125127
}
126-
}
127-
);
128+
);
128129
}
129130

130131
public GraphQLOutputType getType(TypeMeta meta, Annotation[] annotations) {

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/EntityUtil.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ static boolean isContext(Class<?> class1, Annotation[] annotations) {
143143
return true;
144144
}
145145
}
146-
return (
147-
class1.isAssignableFrom(GraphQLContext.class) || class1.isAssignableFrom(DataFetchingEnvironment.class) || class1.isAnnotationPresent(Context.class)
148-
);
146+
return (class1.isAssignableFrom(GraphQLContext.class) || class1.isAssignableFrom(DataFetchingEnvironment.class) || class1
147+
.isAnnotationPresent(Context.class));
149148
}
150149

151150
static <T extends Annotation> T getAnnotation(Class<?> type, Class<T> annotation) {

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/FilteredPublisher.java

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,64 +29,63 @@ public FilteredPublisher(Publisher<T> publisher, RestrictType<T> restrict) {
2929

3030
@Override
3131
public void subscribe(Subscriber<? super T> subscriber) {
32-
publisher.subscribe(
33-
new Subscriber<T>() {
34-
private CompletableFuture<?> current = CompletableFuture.completedFuture(null);
35-
private Subscription s;
32+
publisher
33+
.subscribe(
34+
new Subscriber<T>() {
35+
private CompletableFuture<?> current = CompletableFuture.completedFuture(null);
36+
private Subscription s;
3637

37-
@Override
38-
public void onSubscribe(Subscription s) {
39-
this.s = s;
40-
subscriber.onSubscribe(s);
41-
}
42-
43-
@Override
44-
public void onNext(T t) {
45-
synchronized (this) {
46-
current = current.thenCompose(__ -> restrict.allow(t)).whenComplete(process(subscriber, t));
38+
@Override
39+
public void onSubscribe(Subscription s) {
40+
this.s = s;
41+
subscriber.onSubscribe(s);
4742
}
48-
}
4943

50-
private BiConsumer<Boolean, Throwable> process(Subscriber<? super T> subscriber, T t) {
51-
return (allow, error) -> {
52-
if (error != null) {
53-
subscriber.onError(error);
54-
return;
44+
@Override
45+
public void onNext(T t) {
46+
synchronized (this) {
47+
current = current.thenCompose(__ -> restrict.allow(t)).whenComplete(process(subscriber, t));
5548
}
56-
if (allow) {
57-
subscriber.onNext(t);
58-
} else {
59-
s.request(1);
60-
}
61-
};
62-
}
49+
}
6350

64-
@Override
65-
public void onError(Throwable t) {
66-
synchronized (this) {
67-
current =
68-
current.whenComplete((__, error) -> {
51+
private BiConsumer<Boolean, Throwable> process(Subscriber<? super T> subscriber, T t) {
52+
return (allow, error) -> {
53+
if (error != null) {
54+
subscriber.onError(error);
55+
return;
56+
}
57+
if (allow) {
58+
subscriber.onNext(t);
59+
} else {
60+
s.request(1);
61+
}
62+
};
63+
}
64+
65+
@Override
66+
public void onError(Throwable t) {
67+
synchronized (this) {
68+
current = current.whenComplete((__, error) -> {
6969
if (error != null) {
7070
subscriber.onError(error);
7171
}
7272
subscriber.onError(t);
7373
});
74+
}
7475
}
75-
}
7676

77-
@Override
78-
public void onComplete() {
79-
synchronized (this) {
80-
current =
81-
current.whenComplete((__, error) -> {
77+
@Override
78+
public void onComplete() {
79+
synchronized (this) {
80+
current = current.whenComplete((__, error) -> {
8281
if (error != null) {
8382
subscriber.onError(error);
8483
}
8584
subscriber.onComplete();
8685
});
86+
}
8787
}
8888
}
89-
}
90-
);
89+
);
9190
}
9291
}

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/SchemaBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public GraphQLSchema.Builder build() {
126126
try {
127127
Reflections reflections = new Reflections(classpaths, Scanners.SubTypes, Scanners.MethodsAnnotated, Scanners.TypesAnnotated);
128128
Set<Class<? extends Authorizer>> authorizers = reflections.getSubTypesOf(Authorizer.class);
129-
//want to make everything split by package
129+
// want to make everything split by package
130130
AuthorizerSchema authorizer = AuthorizerSchema.build(dataFetcherRunner, new HashSet<>(classpaths), authorizers);
131131

132132
Set<Class<? extends SchemaConfiguration>> schemaConfiguration = reflections.getSubTypesOf(SchemaConfiguration.class);

graphql-builder/src/main/java/com/phocassoftware/graphql/builder/annotations/Context.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919

2020
@Retention(RUNTIME)
2121
@Target({ ElementType.TYPE, ElementType.PARAMETER })
22-
public @interface Context {
23-
}
22+
public @interface Context {}

0 commit comments

Comments
 (0)