Comments (10)
Here's my take on the above, in case anyone's interested: https://medium.com/@dSebastien/graphql-api-integration-tests-in-a-spring-boot-2-x-kotlin-application-5840d3c5d66f
HTH! :)
from graphql-spring-boot.
With a little help from the example of @dsebastien and the effort of @mxab we added the first version of graphql-spring-boot-starter-test that should help with writing your tests. See example-graphql-tools for example how to use it.
from graphql-spring-boot.
The issue seems to be that MockMvc isn't working with servlets. A workaround is to disable the servlet mapping and add spring wrapper controller like so:
@RestController
public class GQLController {
@Autowired
private GraphQLServlet graphQLServlet;
@RequestMapping("graphql")
public void graphql(HttpServletRequest request, HttpServletResponse response) throws Exception {
graphQLServlet.service(request, response);
}
}
from graphql-spring-boot.
from graphql-spring-boot.
from graphql-spring-boot.
Would like that as well
from graphql-spring-boot.
That certainly helps, but I'm struggling specifically with the part how to ensure that not my entire context is auto loaded, and that only the relevant GraphQL part is loaded. How did you solve that? Do you include a specific configuration for your test, or do you exclude all the stuff you don't need?
The other stuff (Jpa, MVC controllers, etc) which I don't need for the GraphQL part takes too long to load for my tests, so I'm looking for a way to cut that load time considerably.
from graphql-spring-boot.
The maintenance of that is indeed a big downside.. I'll stick with the entire context for now, thanks!
from graphql-spring-boot.
How do you maintain the test queries? As escaped Strings in code or within separate files?
I'd like to put my test queries in dedicated (.graphql) files, for example:
mutation {
createThing(name: "foo", description: "bar") {
uuid,
name,
description
}
}
And an easy way in Java to convert the above to what I actually need to send over the wire:
{
"query": "mutation {\n createThing(name: \"e\", description: \"cool\") {\n uuid,\n name,\n description\n }\n}",
"variables": null
}
Has anyone done this yet? :)
from graphql-spring-boot.
I had an issue with using GraphQLTestTemplate provided with spring-boot-starter-test where my tests were @Transactional
.
If I annotated tests with @Transactional
and say I created a new record in a table (Obviously it wasn't committed yet as the test execution hasn't completed). Then I invoked a query using GraphQLTestTemplate, the resolvers were not able to see the created record. This is because GraphQLTestTemplate uses TestRestTemplate which invokes a http call, so when the execution comes to the resolvers a new Transaction is created, and this transaction doesn't have access to the entities created before.
If I get rid of @Transactional
from test, then the test works fine, as the record is actually committed into the DB. But the side effect is that test records are now in the DB, and other integration tests running might break.
So, to support transactional integration testing I created a custom Tester here. You just need to autowire it into your test and use it. It usage is exactly the same as GraphQLTestTemplate
, except it will ensure to maintain the Transactional context of test cases when annotated with @Transactional
.
Although the issue is closed, I added this comment in case someone else comes looking for a similar requirement just like I did.
from graphql-spring-boot.
Related Issues (20)
- Customize SimpleDataFetcherExceptionHandler to avoid logException for certain errors HOT 1
- Spring Boot Graphql Remove duplicates from the Response
- SpringDoc bean name conflict error HOT 1
- Latest 15.0.0 version is not compatible with Spring boot 3.0.2 and spring security 6.0.1 HOT 3
- Possibility to add authorization headers to the GraphQLTestSubscription HOT 14
- How to set the bearer token dynamically in graphql-spring-boot playground
- different data response for nullable and non-nullable responses
- @connection not working after Spring Boot and graphql upgrade HOT 1
- CVE-2023-28867 affects all recent versions (including v15)
- `ErrorHandlerSupplier` not always initialized when we first need it
- Query returning the result of previously timed out query
- Support check origin for websocket to secure against cross-site attacks
- Support CSRF on websockets to secure against cross-site attacks
- When upgrading to Spring Boot 3.1.0 we get in the response the tracing information under extensions HOT 2
- MetricsInstrumentation does not implement updated API of TracingInstrumentation provided by graphql-java
- Maven seems to confuse graphql-java version HOT 4
- Request scoped beans aren't accessible in mutation and query resolvers
- Virtual threads support
- Cannot disable tracing response with graphql-spring-boot-starter version 15 HOT 4
- No qualifying bean of type 'com.graphql.spring.boot.test.GraphQLTestTemplate' available : graphql-spring-boot-starter-test:jar:15.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-spring-boot.