Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): Graphql update #448

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ jobs:
run: ./sh_generate_project.sh reactive
- name: Scan generated reactive project dependencies
if: steps.changes.outputs.templates == 'true'
working-directory: ./build/toscan
working-directory: ./build/toscan/reactive
run: ./gradlew build it
# run: ./gradlew build dependencyCheckAnalyze && ./gradlew it && cat applications/app-service/build/reports/dependency-check-sonar.json
- name: Sonar analysis for generated reactive project
if: github.event.pull_request.head.repo.fork == false && steps.changes.outputs.templates == 'true'
working-directory: ./build/toscan
working-directory: ./build/toscan/reactive
run: ./gradlew sonar --stacktrace
-Dsonar.token=${{ secrets.SONAR_TOKEN_GENERATED }}
env:
Expand All @@ -90,12 +90,12 @@ jobs:
run: ./sh_generate_project.sh imperative
- name: Scan generated imperative project dependencies
if: steps.changes.outputs.templates == 'true'
working-directory: ./build/toscan
working-directory: ./build/toscan/imperative
run: ./gradlew build it
# run: ./gradlew build dependencyCheckAnalyze && ./gradlew it && cat applications/app-service/build/reports/dependency-check-sonar.json
- name: Sonar analysis for generated imperative project
if: github.event.pull_request.head.repo.fork == false && steps.changes.outputs.templates == 'true'
working-directory: ./build/toscan
working-directory: ./build/toscan/imperative
run: ./gradlew sonar --stacktrace
-Dsonar.token=${{ secrets.SONAR_TOKEN_GENERATED_I }}
env:
Expand Down
13 changes: 7 additions & 6 deletions sh_generate_project.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
set -e
TYPE=$1
echo "Generating project with type $TYPE"
MY_DIR="build/toscan/$TYPE"
echo "Generating project with type $TYPE in $MY_DIR"

rm -rf build/toscan
mkdir build/toscan
rm -rf $MY_DIR
mkdir -p $MY_DIR
echo "buildscript {
repositories {
mavenLocal()
Expand All @@ -17,9 +18,9 @@ echo "buildscript {
}
}

apply plugin: 'co.com.bancolombia.cleanArchitecture'" >> build/toscan/build.gradle
apply plugin: 'co.com.bancolombia.cleanArchitecture'" >> $MY_DIR/build.gradle

cd build/toscan || exit
cd $MY_DIR || exit
gradle ca --metrics false --example true --type $TYPE
gradle wrapper

Expand All @@ -40,7 +41,7 @@ else
./gradlew gda --type $adapter
done

for entry in "mq" "restmvc" "sqs"
for entry in "mq" "restmvc" "sqs" "graphql"
do
./gradlew gep --type $entry
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@
import co.com.bancolombia.exceptions.CleanException;
import co.com.bancolombia.factory.ModuleBuilder;
import co.com.bancolombia.factory.ModuleFactory;
import co.com.bancolombia.factory.validations.ReactiveTypeValidation;
import java.io.IOException;

public class EntryPointGraphql implements ModuleFactory {

@Override
public void buildModule(ModuleBuilder builder) throws IOException, CleanException {
builder.runValidations(ReactiveTypeValidation.class);
String path = builder.getStringParam("task-param-pathgql");
if (!path.startsWith("/")) {
throw new IllegalArgumentException("The path must start with /");
}
builder.appendToSettings("graphql-api", "infrastructure/entry-points");
builder.appendToProperties("graphql.servlet").put("enabled", true).put("mapping", path);
builder
.appendToProperties("graphql.playground")
.put("mapping", "/playground")
.put("endpoint", path)
.put("enabled", true);
builder.appendToProperties("spring.graphql.graphiql").put("enabled", false);
builder.addParam("reactive", builder.isReactive());

String dependency = buildImplementationFromProject(builder.isKotlin(), ":graphql-api");
builder.appendDependencyToModule(APP_SERVICE, dependency);

builder.setupFromTemplate("entry-point/graphql-api");
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
package {{package}}.graphqlapi;

import graphql.kickstart.tools.GraphQLMutationResolver;
{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.stereotype.Controller;
{{#reactive}}
import reactor.core.publisher.Mono;
{{/reactive}}

{{#lombok}}
@RequiredArgsConstructor
{{/lombok}}
@Controller
/**
* To interact with the API make use of Playground in the "/playground" path, but remember,
* Playground ONLY must be used in dev or qa environments, not in production.
*/
public class ApiMutations implements GraphQLMutationResolver {
public class ApiMutations {

// private final MyUseCase useCase;
//private final MyUseCase useCase;

{{^lombok}}
//public ApiMutations(MyUseCase useCase){
// this.useCase = useCase;
//}
{{/lombok}}

public String addSomething(String objRequest/* change for object request */) {
// return useCase.doAction(objRequest);
{{#reactive}}
@MutationMapping
public Mono<String> addSomething(@Argument("objectRequest") String objRequest/* change for object request */) {
//return useCase.doAction(objRequest);
return Mono.just("Hello world from graphql-api mutations " + objRequest);
}
{{/reactive}}
{{^reactive}}
@MutationMapping
public String addSomething(@Argument("objectRequest") String objRequest/* change for object request */) {
//return useCase.doAction(objRequest);
return "Hello world from graphql-api mutations " + objRequest;
}
{{/reactive}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ package {{package}}.graphqlapi;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
{{#reactive}}
import reactor.test.StepVerifier;
{{/reactive}}

public class ApiMutationsTest {

{{#reactive}}
@Test
void addSomethingTest(){
ApiMutations apiMutations = new ApiMutations();
var objRequest = "objRequest";
apiMutations.addSomething(objRequest)
.as(StepVerifier::create)
.assertNext(Assertions::assertNotNull)
.verifyComplete();
}
{{/reactive}}
{{^reactive}}
@Test
void addSomethingTest(){
ApiMutations apiMutations = new ApiMutations();
Expand All @@ -13,4 +28,5 @@ public class ApiMutationsTest {

Assertions.assertNotNull(addSomething);
}
{{/reactive}}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package {{package}}.graphqlapi;

import graphql.kickstart.tools.GraphQLQueryResolver;
{{#lombok}}
import lombok.RequiredArgsConstructor;
{{/lombok}}
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.stereotype.Controller;
{{#reactive}}
import reactor.core.publisher.Mono;
{{/reactive}}

{{#lombok}}
@RequiredArgsConstructor
@RequiredArgsConstructor
{{/lombok}}
@Controller
/**
* To interact with the API make use of Playground in the "/playground" path, but remember,
* To interact with the API make use of Playground in the "/graphiql" path, but remember,
* Playground ONLY must be used in dev or qa environments, not in production.
*/
public class ApiQueries implements GraphQLQueryResolver {
public class ApiQueries {

// private final MyUseCase useCase;

Expand All @@ -24,8 +28,18 @@ public class ApiQueries implements GraphQLQueryResolver {
//}
{{/lombok}}

public String getSomething(String objRequest/* change for object request */) {
// return useCase.doAction(objRequest);
return "Hello world from graphql-api queries " + objRequest;
{{#reactive}}
@QueryMapping
public Mono<String> getSomething(@Argument("id") String id/* change for object request */) {
//return useCase.doAction(objRequest);
return Mono.just("Hello world from graphql-api queries " + id);
}
{{/reactive}}
{{^reactive}}
@QueryMapping
public String getSomething(@Argument("id") String id/* change for object request */) {
//return useCase.doAction(objRequest);
return "Hello world from graphql-api queries " + id;
}
{{/reactive}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ package {{package}}.graphqlapi;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
{{#reactive}}
import reactor.test.StepVerifier;
{{/reactive}}

public class ApiQueriesTest {

{{#reactive}}
@Test
void addSomethingTest(){
ApiQueries apiQueries = new ApiQueries();
var objRequest = "objRequest";
apiQueries.getSomething(objRequest)
.as(StepVerifier::create)
.assertNext(Assertions::assertNotNull)
.verifyComplete();
}
{{/reactive}}
{{^reactive}}
@Test
void addSomethingTest(){
ApiQueries apiQueries = new ApiQueries();
Expand All @@ -13,4 +28,5 @@ public class ApiQueriesTest {

Assertions.assertNotNull(addSomething);
}
{{/reactive}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ dependencies {
implementation project(':model')
implementation project(':usecase')
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'com.graphql-java-kickstart:graphql-spring-boot-starter:{{GRAPHQL_KICKSTART_VERSION}}'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
}
2 changes: 0 additions & 2 deletions src/main/resources/entry-point/graphql-api/definition.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"folders": [
"infrastructure/entry-points/graphql-api/src/main/{{language}}/{{packagePath}}/graphql-controllers",
"infrastructure/entry-points/graphql-api/src/test/{{language}}/{{packagePath}}/graphql-controllers",
"applications/app-service/src/main/resources/graphql"
],
"files": {},
Expand Down
Loading