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

reproducer for #1681 #1682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
72 changes: 72 additions & 0 deletions examples/spring-data-spqr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@
<artifactId>jakarta.annotation-api</artifactId>
<version>${version.annotation}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>blaze-persistence-entity-view-processor</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -221,6 +227,72 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>${project.build.directory}/metamodel</outputDirectory>
<processors>
<processor>com.blazebit.persistence.view.processor.EntityViewAnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies>
<!-- Metamodel -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>blaze-persistence-entity-view-processor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${version.jaxb-api}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${version.jaxb}</version>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>${version.jta}</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>${version.activation}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source-metamodel</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public CriteriaBuilderFactory createCriteriaBuilderFactory() {
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Lazy(false)
public EntityViewManager createEntityViewManager(CriteriaBuilderFactory cbf, EntityViewConfiguration entityViewConfiguration) {
// entityViewConfiguration.getProperties().setProperty("com.blazebit.persistence.view.static_implementation_scanning_disabled", "true");
return entityViewConfiguration.createEntityViewManager(cbf);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.blazebit.persistence.examples.spring.data.spqr.repository.CatViewRepository;
import com.blazebit.persistence.examples.spring.data.spqr.view.CatCreateView;
import com.blazebit.persistence.examples.spring.data.spqr.view.CatWithOwnerView;
import com.blazebit.persistence.examples.spring.data.spqr.view.ChildInput;
import com.blazebit.persistence.examples.spring.data.spqr.view.ChildView;
import com.blazebit.persistence.examples.spring.data.spqr.view.PersonSimpleView;
import com.blazebit.persistence.integration.graphql.GraphQLEntityViewSupport;
import com.blazebit.persistence.view.EntityViewManager;
import com.blazebit.persistence.view.EntityViewSetting;
Expand Down Expand Up @@ -76,4 +79,13 @@ public Long createCat(@GraphQLArgument(name = "cat") CatCreateView cat) {
repository.save(cat);
return cat.getId();
}

@GraphQLMutation
public Long addPersonChild(@GraphQLArgument(name = "child") ChildInput childInput, @GraphQLArgument(name = "personId") Long personId) {
PersonSimpleView person = repository.findById(EntityViewSetting.create(PersonSimpleView.class), personId);
ChildView child = (childInput.getBoy() != null) ? childInput.getBoy() : childInput.getGirl();
person.getChildren().add(child);
repository.save(person);
return child.getId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2014 - 2023 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.blazebit.persistence.examples.spring.data.spqr.view;

import io.leangen.graphql.annotations.types.GraphQLType;

/**
* @author Christian Beikov
* @since 1.6.4
*/
@GraphQLType(name = "ChildInput")
public class ChildInput {
BoyView boy;
GirlView girl;

public BoyView getBoy() {
return boy;
}

public void setBoy(BoyView boy) {
this.boy = boy;
}

public GirlView getGirl() {
return girl;
}

public void setGirl(GirlView girl) {
this.girl = girl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.blazebit.persistence.examples.spring.data.spqr.view;

import com.blazebit.persistence.examples.spring.data.spqr.model.Child;
import com.blazebit.persistence.view.CreatableEntityView;
import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.EntityViewInheritance;
import com.blazebit.persistence.view.IdMapping;
Expand All @@ -26,7 +27,9 @@
* @author Christian Beikov
* @since 1.6.4
*/
@GraphQLUnion(name = "Child", possibleTypeAutoDiscovery = true)
// Can't use possibleTypeAutoDiscovery=true because of the generated EV implementations
@GraphQLUnion(name = "Child", possibleTypes = {BoyView.class, GirlView.class})
@CreatableEntityView
@EntityView(Child.class)
@EntityViewInheritance
public interface ChildView {
Expand All @@ -35,4 +38,6 @@ public interface ChildView {
Long getId();

String getName();

void setName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

import com.blazebit.persistence.examples.spring.data.spqr.model.Person;
import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.UpdatableEntityView;

import java.util.Set;

/**
* @author Christian Beikov
* @since 1.6.4
*/
@UpdatableEntityView
@EntityView(Person.class)
public interface PersonSimpleView extends PersonIdView {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* @author Christian Beikov
Expand Down Expand Up @@ -106,6 +107,22 @@ public void testCreate() {
assertEquals("PersonSimpleView", response.getBody().get("data").get("catById").get("owner").get("__typename").asText());
}

@Test
public void testCreateInheritance() {
String requestGraphQL = "mutation {\n" +
" addPersonChild(\n" +
" child: {\n" +
" boy: { name: \"Test\" }\n" +
" },\n" +
" personId: 3\n" +
" )\n" +
"}";
HttpHeaders headers = new HttpHeaders();
headers.add("content-type", "application/graphql");
ResponseEntity<JsonNode> response = this.restTemplate.postForEntity("/graphql", new HttpEntity<>(requestGraphQL, headers), JsonNode.class);
assertNull(response.getBody().get("errors"));
}

static String request(int first, String after) {
String other = "";
if (after != null) {
Expand Down